【发布时间】:2009-05-19 19:35:01
【问题描述】:
页面具有角色。用户有角色。一个用户只能查看一个页面,如果他和它共享一个或多个角色。
这行得通:
Dim Allow As Boolean = False
CurrentPage.Roles.Load()
For Each r As Role In CurrentPage.Roles
r.Users.Load()
For Each u As User In r.Users
If u.Id = CurrentUser.Id Then
Allow = True
Exit For
End If
Next
If Allow Then
Exit For
End If
Next
如果我可以使用 LINQ 或 lambda 表达式用更少的代码行来代替,我不想使用嵌套循环。
这总是返回 False:
Dim Allow As Boolean = (CurrentPage.Roles.ToList.Intersect(CurrentUser.Roles.ToList).Count > 0)
我认为它失败了,因为角色是实体对象。
如何让它只比较 Role Id 值以确定相等性?
【问题讨论】:
标签: .net vb.net entity-framework generics