Entity Framework strategy/approach -
well, here goes noob question: made app different customer have access accounts. ok, login, roles can gets though entity framework. thing is, time, database grow lot. example: customers have access "bills pay". now, there couple thousand of them , simple "where" lambda expression can trick. said, base grow. scenario: every record, has "company" field, determines company record belongs to. users have roles, store companies specific user can access data. 1 user can access multiple companies data if configured way. question is: there way initialize entity framework scope passing on user's roles scope contains data "belong" user? like:
using (mythingy scope = new mythingy(user.roles)) { //scope.bills here contain bills "payer" or "holder" //are companies within user.roles list<bill> billstopay = scope.bills.where(c => c.duedate == datetime.now); }
so, possible? if so, best approach?
there many ways this. may want read on joins. here couple of approaches may work:
// brings lot of bills db memory...... using (dbcontext scope = new dbcontext()) { //scope.bills here contain bills "payer" or "holder" //are companies within user.roles ienumerable<bill> billstopay = scope.bills.where(c => c.duedate == datetime.now ); // part happens in memory list<bill> bills = billstopay .where(c => user.roles.any(role => c.payer == role.payer || c.holder == role.holder)) .tolist(); } // more efficient.. did memory. syntax may not perfect.... using (dbcontext scope = new dbcontext()) { //scope.bills here contain bills "payer" or "holder" //are companies within user.roles var query = u in scope.users role in u.roles b in scope.bills.where(b => b.duedate == datetime.now && (b.roleid == role.roleid || b.holderid == role.holderid)) u.userid == user.userid select b; }
Comments
Post a Comment