C
C#2w ago
Rai

EFCore Multi-level relation

I have been wondering if it is possible to describe a multi level relation using the fluent api from EFCore. For example
class User{
public ICollection<Group> MemberOfGroups;
}

public class Group {
public ICollection<GroupRole> Roles;
}

public class GroupRole{
public ICollection<User> Members;
}
class User{
public ICollection<Group> MemberOfGroups;
}

public class Group {
public ICollection<GroupRole> Roles;
}

public class GroupRole{
public ICollection<User> Members;
}
where MemberOfGroups is based on the Members from Roles from the Group?
3 Replies
Ishan
Ishan2w ago
Confused about question
Joschi
Joschi2w ago
Yes such relations are possible. You just define each relationship individually. But I don't understand what you are asking in the last sentence?
this_is_pain
this_is_pain2w ago
there is nothing unusual for now you have to define all the primary keys and then which direction you want the relationship (so for example if Group should have an FK to User or if there should be a third relationships table)

Did you find this page helpful?