我正在尝试在我的 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'.