views:

148

answers:

2

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.PermissionLevel.Value descending
select permissions

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

Thanks! Kelly

+1  A: 
        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)
John
+3  A: 

Like this:

user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions)
                  .Where(permissions => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read")
                  .OrderByDescending(permissions => permissions.PermissionLevel.Value)
SLaks
Ahh...SelectMany! I'll read up on that. Thanks a lot!
Jinkinz
ReSharper has a nice feature that automatically translates query syntax to 'method chain' and (sometimes) vice versa. [note: I'm not related to jetbrains]
jeroenh