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 business layer.How can i add automaticly filter to requests.
My GetList method in DAL
public List<TEntity> GetList(Expression<Func<TEntity, bool>> filter)
{
using (var context = new TContext())
{
return filter == null
? context.Set<TEntity>().ToList()
: context.Set<TEntity>().Where(filter).ToList();
}
}
Business
public List<FinanceData> GetAll()
{
return _financeDal.GetList(filter:x=>x.CompanyID==_cID);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…