I am trying to get data from 3 entities. Exam, Objective and Objective detail. I want to be able to select this by exam name. Here is the code I am using:
var result = await db.Exams
.Include(e => e.Objectives)
.Include(e => e.Objectives.SelectMany(o => o.ObjectiveDetails))
.Where(e => e.Name == name)
.FirstOrDefaultAsync();
This is giving me an error message when I run it saying:
exceptionMessage=The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path
Can someone advise me what I am doing wrong. Here's my classes:
public class Exam
{
public Exam()
{
this.Objectives = new HashSet<Objective>();
}
public int ExamId { get; set; }
public int SubjectId { get; set; }
public virtual ICollection<Objective> Objectives { get; set; }
}
public class Objective : AuditableTable
{
public Objective()
{
this.ObjectiveDetails = new HashSet<ObjectiveDetail>();
}
public int ObjectiveId { get; set; }
public int ExamId { get; set; }
public int Number { get; set; }
public virtual Exam Exam { get; set; }
public virtual ICollection<ObjectiveDetail> ObjectiveDetails { get; set; }
}
public partial class ObjectiveDetail
{
public int ObjectiveDetailId { get; set; }
public int ObjectiveId { get; set; }
public int Number { get; set; }
public string Text { get; set; }
public virtual Objective Objective { get; set; }
}