Пример #1
0
        public static List <T> get <T>(Expression <Func <T, bool> > where  = null,
                                       Expression <Func <T, int> > orderBy = null
                                       , bool firstOrLirst = true, int?top = null) where T : class
        {
            using (var context = new dbEntities())
            {
                IQueryable <T> result = context.Set <T>();
                if (where != null)
                {
                    result = result.Where(where);
                }

                if (orderBy != null)
                {
                    if (firstOrLirst)
                    {
                        result = result.OrderBy(orderBy);
                    }
                    else
                    {
                        result = result.OrderByDescending(orderBy);
                    }
                }

                if (top != null)
                {
                    result = result.Take((int)top);
                }

                return(result.ToList());
            }
        }
Пример #2
0
 public static void insert <T>(T Tentity) where T : class
 {
     using (var context = new dbEntities())
     {
         context.Set <T>().Add(Tentity);
         context.SaveChanges();
     }
 }
Пример #3
0
 public GenericRepository(dbEntities db)
 {
     _db    = db;
     _dbSet = _db.Set <T>();
 }