将此 Linq 查询从查询​​语法转换为 lambda 表达式

发布于 2024-09-02 04:56:51 字数 412 浏览 2 评论 0原文

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

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

谢谢! 凯莉

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神魇的王 2024-09-09 04:56:51

像这样:

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

Like this:

user.SecurityRoles.SelectMany(securityRoles => securityRoles.Permissions)
                  .Where(permissions => permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read")
                  .OrderByDescending(permissions => permissions.PermissionLevel.Value)
北斗星光 2024-09-09 04:56:51
        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)
        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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文