Exemplo n.º 1
0
        public static TEntity SingleOrDefault(TestGeorgeContext context, Expression <Func <TEntity, bool> > whereClause, params Expression <Func <TEntity, object> >[] includes)
        {
            var result = context.Set <TEntity>().AsQueryable();

            result = includes.Aggregate(result, (current, include) => current.Include(include));
            return(result.SingleOrDefault(whereClause));
        }
Exemplo n.º 2
0
 public static void Add(TEntity entity)
 {
     using (var context = new TestGeorgeContext())
     {
         context.Set <TEntity>().Add(entity);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public static List <TEntity> Where(Expression <Func <TEntity, bool> > whereClause, params Expression <Func <TEntity, object> >[] includes)
 {
     using (var context = new TestGeorgeContext())
     {
         var result = context.Set <TEntity>().Where(whereClause);
         result = includes.Aggregate(result, (current, include) => current.Include(include));
         return(result.ToList());
     }
 }
Exemplo n.º 4
0
 public static List <TEntity> GetAll(params Expression <Func <TEntity, object> >[] includes)
 {
     using (var context = new TestGeorgeContext())
     {
         var result = context.Set <TEntity>().AsQueryable();
         result = includes.Aggregate(result, (current, include) => current.Include(include));
         return(result.ToList());
     }
 }
Exemplo n.º 5
0
 public static TEntity Update(TEntity toUpdate, Expression <Func <TEntity, bool> > whereClause)
 {
     using (var context = new TestGeorgeContext())
     {
         var result = context.Set <TEntity>().SingleOrDefault(whereClause);
         context.Entry(result).CurrentValues.SetValues(toUpdate);
         context.SaveChanges();
         return(toUpdate);
     }
 }
Exemplo n.º 6
0
 public static void Delete(Expression <Func <TEntity, bool> > whereClause)
 {
     using (var context = new TestGeorgeContext())
     {
         var entity = SingleOrDefault(whereClause);
         if (entity != null)
         {
             var result = context.Set <TEntity>().Remove(entity);
             context.SaveChanges();
         }
     }
 }