Reputation: 3360
Users have many Roles. Roles have many Privileges. I need to get a list of privileges assigned to user based on roles user may have. I have something like this in mind but it gives me an IEnumerable of IEnumerable of Privilege:
List<Privilege> privileges = user.Roles.Select(r=>r.Privileges.Where(p=>p.IsActive));
How can I do this using navigation properties?
Upvotes: 0
Views: 221
Reputation: 2079
Try this:
user.Roles.SelectMany(r => r.Privileges).Where(p=>p.IsActive).ToList();
Upvotes: 1