0
页面具有角色。用户具有角色。如果用户和他共享一个或多个角色,用户只能查看页面。如何轻松判断两个.NET EntityObjects集合是否包含任何相同的对象?
这工作:
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)
我想是因为角色是EntityObjects失败。
我怎样才能让它只比较角色ID值来确定相等?