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()); } }
public static void insert <T>(T Tentity) where T : class { using (var context = new dbEntities()) { context.Set <T>().Add(Tentity); context.SaveChanges(); } }
public GenericRepository(dbEntities db) { _db = db; _dbSet = _db.Set <T>(); }