使用导航属性的实体框架查询 [英] Entity Framework query using navigation properties
本文介绍了使用导航属性的实体框架查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用户具有许多角色.角色有许多特权.我需要获取基于用户可能具有的角色分配给用户的特权的列表.我的想法是这样的,但这给了我IEnumerable IEnumerable of Privilege:
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?
推荐答案
SelectMany
随着您的前进,它变平了无数
It flattens the ienumerables as you go
这篇关于使用导航属性的实体框架查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文