开发者

Convert this Linq query from query syntax to lambda expression

I'm not sure I like linq query syntax...its just not my preference. But I don't know what this query would look like using lambda expressions, can someone help?

from securityRoles in user.SecurityRoles
from permissions in securityRoles.Permissions
where permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read"
orderby permissions.Permissio开发者_C百科nLevel.Value descending
select permissions

There is a many-to-many relationship between users and security roles that makes this extra confusing.

Thanks! Kelly


Like this:

user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions)
                  .Where(permissions => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read")
                  .OrderByDescending(permissions => permissions.PermissionLevel.Value)


        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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜