I have the following scenario to solve, using entity framework and a database first approach:
A table Student
having the fields:
ID (PK), Name, Surname
And a table StudentsFriends
that basically tells me what students are related to another, having the fields:
StudentID, FriendID
For instance, the latter table content could be:
StudentID, FriendID,
1 2
1 3
2 3
2 1
What I'd like to achieve is creating an association with a navigation property on the Student entity which tells me the list of friends, using the vs built in model browser. The generated entity would look something like this:
public class Student
{
public int ID;
public string Name;
public string Surname;
public ICollection<Student> Friends;
}
In the example above Student 1
is Friends with Student 2, Student 3
and Student 2
is friends with Student 3, Student 1
. Student 3
has no friends.
However I have no idea how to achieve that: I only managed to create association between entities, and if I create an association on the same entity I can't "reference" the table to join them.
Thansk in advance for the help.