c# - Entity Framework - Linq to query where value in a list -


i'm using entity framework on .net 3.5 , can't life of me figure out how write linq traverse following design:

basically trying figure out if user has permission (entityaction) specific entitytype. users , roles maintained in active directory - system can lookup find role/groups user belongs.

let's assume have following data:

entitytype

entitytypeid: 1

name: entity one

user

userid: 1

accountname: andez

role

roleid: 1

accountname: myrole

entityaction

entityactionid: 1

name: something

roleentityactionassociation

(association between role , entityaction)

entityactionid: 1

roleid: 1

i storing group names user (from active directory) in list:

list<string> groupnames = new list<string>(); 

question

however trying piece linq find out whether user (or 1 of roles assigned in list groupnames) associated particular entityaction given entitytype.

// reference user user user = context.users.where(x => x.accountname == "andez").firstordefault();  // reference entity type want query entitytype et = context.entitytypes.where(x => x.name == "entity one").firstordefault();  // list of entity actions user var result = ea in et.entityactions              ea.entityactionid == 1 && (ea.users.contains(user) || ea.roles.count(r => groupnames.contains(r.accountname)) > 0)              select ea; 

of course query not work above - not return results (result.tolist().count == 0)

i need pointers on please.

thanks

ef design

maybe need check user id, replace ea.users.contains(user) ea.users.any(us => us.userid == user.userid):

var result = ea in et.entityactions                      ea.entityactionid == 1 && ea.users.any(us => us.userid == user.userid)                      select ea; 

update 0

try code, should work:

var result = ea in et.entityactions                      ea.entityactionid == 1 &&                          (ea.users.any(us => us.userid == user.userid) || ea.any(r => groupnames.contains(r.accountname)))                      select ea; 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -