我不确定我是否喜欢linq查询语法......这不是我的偏好。但我不知道这个查询使用lambda表达式会是什么样的,有人可以帮忙吗?
from securityRoles in user.SecurityRoles
from permissions in securityRoles.Permissions
where permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read"
orderby permissions.PermissionLevel.Value descending
select permissions
用户和安全角色之间存在多对多的关系,这使得这更加令人困惑。
谢谢! 凯利
答案 0 :(得分:5)
像这样:
user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions)
.Where(permissions => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read")
.OrderByDescending(permissions => permissions.PermissionLevel.Value)
答案 1 :(得分:1)
user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions,
(securityRoles, permissions) => new {securityRoles, permissions}).Where(
@t => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read").OrderByDescending(
@t => permissions.PermissionLevel.Value).Select(@t => permissions)