CRUD
You can apply CRUD operations using code like the example you gave in your question:
Create
person.Vrienden.Add(friend);
Read
person.Vrienden;
Update
person.Vrienden.Remove(friend);
otherPerson.Vrienden.Add(friend);
Delete
person.Vrienden.Remove(friend);
Direct access
However, since you want to be able to query for all friendships, perhaps what you're wanting is to materialise the Friendship
concept in your domain model:
public class Friendship
{
public Persoon FriendA { get; set; }
public Persoon FriendB { get; set; }
}
Adjust Persoon
and its mapping so that Vrienden
is an ICollection<Friendship>
. Then adjust your mapping to be one-to-many (one person has many friendships).
Now you can query for all friendships and apply CRUD operations to Friendship
s directly. Note that you'll need to be careful to prevent duplicate friendships since you could have two friendships between the same pair of friends but with reversed order.