I have the following classes:
public class Teacher
{
Guid ID;
string Name;
string Address;
string Tel;
ICollection<Student> Students;
}
public class Student
{
Guid id;
string Name;
string Address;
string Tel;
ICollection<Teacher> Teachers;
}
As this is a Many-to-Many relationship, EF would create a Junction Table TeacherStudent. I want to find all teachers and the list of the teacher's students (name only), eg:
Teacher1 name:
Student1 name,
Student3 name,
Student5 name,
Student9 name
Teacher2 name:
Student1 name,
Student2 name,
Student3 name,
Student9 name
I've tried:
_context.Teacher.Include(x=>x.TeacherStudent).ThenInclude(y=>y.Student);
This works and Student info is a list under each Teacher. However, I don't want all the info, I only want the name. I've tried SelectMany but it flattened out the data and I get the Teacher's name repeated for each Student. How can get a list of Student names under the Teacher's name and not retrieve the fields I don't need ?
Thanks.