Exemple #1
0
 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());
     }
 }
Exemple #2
0
 public virtual void Create(T model)
 {
     using (var context = new AutoContext())
     {
         context.Set <T>().Add(model);
         context.SaveChanges();
     }
 }
Exemple #3
0
 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());
     }
 }