public List <T> Filter(Expression <Func <T, bool> > predicate) { using (ModelContainer1 context = new ModelContainer1()) { return((List <T>)context.Set <T>().Where(predicate).ToList()); } }
public T Single(Expression <Func <T, bool> > predicate) { using (ModelContainer1 context = new ModelContainer1()) { return(context.Set <T>().FirstOrDefault(predicate)); } }
public List <T> GetAll() { using (ModelContainer1 context = new ModelContainer1()) { return((List <T>)context.Set <T>().ToList()); } }
public bool Create(T entity) { using (ModelContainer1 context = new ModelContainer1()) { context.Set <T>().Add(entity); return(context.SaveChanges() > 0); } }
public void Delete(Expression <Func <T, bool> > predicate) { using (ModelContainer1 context = new ModelContainer1()) { var entities = context.Set <T>().Where(predicate).ToList(); entities.ForEach(x => context.Entry(x).State = EntityState.Deleted); context.SaveChanges(); } }
public List <T> Filter(Expression <Func <T, bool> > predicate, List <Expression <Func <T, object> > > includes) { List <string> includelist = new List <string>(); foreach (var item in includes) { MemberExpression body = item.Body as MemberExpression; if (body == null) { throw new ArgumentException("The body must be a member expression"); } includelist.Add(body.Member.Name); } using (ModelContainer1 context = new ModelContainer1()) { DbQuery <T> query = context.Set <T>(); includelist.ForEach(x => query = query.Include(x)); return((List <T>)query.Where(predicate).ToList()); } }