Add filter to all query entity framework

前端 未结 4 1551
孤街浪徒
孤街浪徒 2020-12-18 11:07

I want add CompanyID filter to my all entity framework request.Because each user must see just their records.I dont want add filter (x=>x.CompanyID == cID) all methods in bu

4条回答
  •  囚心锁ツ
    2020-12-18 11:45

    You can also extend the object context and add an extension method that returns IQueryable

    Like

    public class CustomdbContext : DbContext
    {       
        public IQueryable ApplyCustomerFilter(IQueryable query) where TEntity : Customer 
        {
             return query.Where(x => x.CustomerId == customerctxId);
        }
    }
    

提交回复
热议问题