c# - Get top level entity based on lower level criteria being met -
i have below database setup. i'm hoping accomplish search worker in worker tabe , return of businessareas resulting user fall under per diagram. i'm hoping accomplish in lambda expression , return top level businessarea entities. if need workers , through number of processes level i'm wanting require me iterate through different levels till top level.
it sounds want this, business areas single user:
var results = wfe.businessareas .where(ba => ba.processes .any(p => p.workerprocesses .any(wp => wp.userid == "pmarshall")));
or in query syntax:
var results = ba in wfe.businessareas ba.processes.any(p => p.workerprocesses.any(wp => wp.userid == "pmarshall")) select ba;
or alternatively:
var results = ba in wfe.businessareas p in ba.processes wp in p.workerprocesses wp.userid == "pmarshall" select ba;
if you'd find areas users, you'd want this:
var results = (from ba in wfe.businessareas p in ba.processes wp in p.workerprocesses select new { ba, wp.userid }) .distinct() .tolookup(x => x.userid, x => x.ba);
and can access results single user using results["pmarshall"]
.
Comments
Post a Comment