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)
精彩评论