I am trying to get the students from the database and also include the course entities corresponding to them, but it seems that I'm doing something wrong.
this is student class:
public class Student
{
public int StudentID { get; set; }
public string Name { get; set; }
public int CourseID { get; set; }
public virtual Course Course { get; set; }
}
this is course class:
public class Course
{
public int CourseID { get; set; }
public string Name { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
and I retrive the collection of student entities as shown below:
context.Students.Include(i => i.Course).ToList();
If I remove the include method, then I get data, but course property of student object is null.
P.S I am testing it with Postman and with "Include" I am not able to get anything.
If I comment this
public virtual ICollection<Student> Students { get; set; }
everything works fine.
I put the full code on github: