public T ObtainById(int id) { using (var db = new DatabaseDbEntities()) { return(db.Set <T>().FirstOrDefault(x => x.Id == id)); } }
public int Count(Expression <Func <T, bool> > where) { using (var db = new DatabaseDbEntities()) { return(db.Set <T>().Where(where).Count()); } }
public IEnumerable <T> FindBy(QueryParameters <T> queryParameters) { var orderByClass = ObtenerOrderBy(queryParameters); Expression <Func <T, bool> > whereTrue = x => true; var where = (queryParameters.Where == null) ? whereTrue : queryParameters.Where; using (DatabaseDbEntities db = new DatabaseDbEntities()) { if (orderByClass.IsAscending) { return(db.Set <T>().Where(where).OrderBy(orderByClass.OrderBy) .Skip((queryParameters.Page - 1) * queryParameters.Top) .Take(queryParameters.Top).ToList()); } else { return(db.Set <T>().Where(where).OrderByDescending(orderByClass.OrderBy) .Skip((queryParameters.Page - 1) * queryParameters.Top) .Take(queryParameters.Top).ToList()); } } }