public virtual List <T> GetWhere(Expression <Func <T, bool> > expression) { using (var context = new AutoContext()) { var query = context.Set <T>().Where(expression); return(query.ToList()); } }
public virtual void Create(T model) { using (var context = new AutoContext()) { context.Set <T>().Add(model); context.SaveChanges(); } }
public virtual List <T> GetWhereWithIncludes(Expression <Func <T, bool> > expression, params Expression <Func <T, object> >[] includes) { using (var context = new AutoContext()) { IQueryable <T> dataset = context.Set <T>(); if (includes.Any()) { foreach (var item in includes) { dataset = dataset.Include(item); } } if (expression != null) { dataset = dataset.Where(expression); } return(dataset.ToList()); } }