Hi,
Lets say I have EntityA that have multiple of EntityB and EntityB can have multiple of EntityA. For simplicity:
class Student
{
public string Name {get;set;}
public virtual ICollection<Teacher> Teachers{get;set;}
}
class Teacher
{
public string Name {get;set;}
public virtual ICollection<Student> Students{get;set;}
}
I do mapping like this:
HasMany(x => x.Teachers)
.WithMany(x => x.Students)
.Map(x =>
{
x.MapLeftKey("StudentId");
x.MapRightKey("TeacherId");
x.ToTable("StudentTeacher");
});
Lazy loading is turned of.
Then I want to load Student including Teachers (meaning only Name of Teacher) but not other Students and then Teachers curculary. I tried this.
var student = _context.Students.Where(x => x.Name == studentName)
.Include(x=>x.Teachers)
.SingleOrDefault();
But I really get a objects. I only want to load the first level.
How can I do this?