The system has several classes of model (eg, tasks, invoices, reports). For each table, depending on the logged company by some parameter(eg. companyID). And I must for every table, every query, every saving, etc. watch this parameter. Is there a simpler way to tell EF to LINQ to each query add this parameter? In other words, if I enter just:
List<Report> list = db.Reports;
that were selected only relevant records with companyID of logged company like
List<Report> list = db.Reports.Where(r => r.companyID = idOfLoggedComp)
Thanks a lot for answer.
Simple answer is no. EF is completely missing global filters. You must make some wrapper class and hide the query inside custom exposed
IQueryablelike:But this is still very poor workaround because:
So you must correctly handle your loading in the application.
The only solution which EF provides is called Conditional mapping but it is hardcoded single filtering condition directly in EDMX so your application would work only for single company.