0
我想從我的LINQ查詢中的對象父項添加一個字段,但它不工作。這裏是我的課:如何在LINQ中包含來自父對象的字段?
public Problem()
{
this.Questions = new List<Question>();
}
public int ProblemId { get; set; }
public int SubTopicId { get; set; }
public string Text { get; set; }
public virtual SubTopic SubTopic { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
public class Question : AuditableTable
{
public int QuestionId { get; set; }
public int ProblemId { get; set; }
public virtual Problem Problem { get; set; }
public virtual QuestionStatus QuestionStatus { get; set; }
}
var questions = _questionsRepository
.GetAll()
.Include(q => q.Problem.SubTopicId)
.Include(q => q.Answers)
.ToList();
我得到這個錯誤:
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=A specified Include path is not valid.
The EntityType 'Models.Contexts.Problem' does not declare a navigation
property with the name 'SubTopicId'.