c# - EF Query - SQL "IN" - Same Table -
i need list of users
whom have relationship organization
, if current user has relationship same organization
.
in other words, if current user not have relationship organization in question, no results returned. if there relationship, results returned. query have right now, retrieving 1 user beingness current user.
the query below active userorganization
records organizationid
matches value passed in query. question is, how know take current user (userid
) , create sure exist within result set before returning records should not able see?
var dbusers = db.userorganizations .where(u => u.organizationid == organizationid) .whereif(active, u => u.isactive)
var dbusers = db.organizations .where(o => o.organizationid == organizationid && o.users.any(u=>u.userid == currentuserid && u.isactive)) .selectmany(o=>o.users)
if can't see users
through organization
can this:
var dbusers = db.organizations .where(o => o.organizationid == organizationid && o.userorganizations.any(u=>u.user.userid == currentuserid && u.user.isactive)) .selectmany(o=>o.userorganizations) .select(uo=>uo.user)
c# entity-framework linq-to-sql
No comments:
Post a Comment