c# - How can I determine if an entity collection contains one of several possible values? -
With .Net Entity Framework and Linq, I'm having trouble finding the best (i.e. the easiest / read / understand )
Consider the implementation of original membership / roles, where the user has a role collection.
What's the best way to say "best" is to say "Does this user have the following roles: Role 1, Role 2, or Role 3?"
I can do it with 1 role to check, like:
if myUser.Roles.Contains (role1) {// do something}
Is there any easy way to add more roles in this check?
If the list of roles is known at compiled time, then you can do something like this:
if (myUser.Roles.Count (R => RIID == role1.Id || R.Id == role2.Id)> 0) {// do something}
If you want to check against the dynamics Lily-built list of roles, it becomes intriguing to tell me that this is what you need to do.
edit change to
from any () calculation ()> 0
- I missed this limit in L2E versus L2SQL.
Comments
Post a Comment