2

我不确定我是否喜欢 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

用户和安全角色之间存在多对多的关系,这使得这更加令人困惑。

谢谢!凯利

4

2 回答 2

5

像这样:

user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions)
                  .Where(permissions => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read")
                  .OrderByDescending(permissions => permissions.PermissionLevel.Value)
于 2010-05-21T02:29:46.337 回答
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)
于 2010-05-21T02:26:32.287 回答