public async Task <T> FirstOrDefaultAsync(System.Linq.Expressions.Expression <Func <T, bool> > filter, System.Linq.Expressions.Expression <Func <T, T> > selector = null, System.Linq.Expressions.Expression <Func <T, object> > include = null) { using (var db = new L2DBContext()) { IQueryable <T> query; if (include != null) { query = db.GetTable <T>().LoadWith(include); } else { query = db.GetTable <T>(); } if (filter != null) { query = query.Where(filter); } if (selector != null) { query = query.Select(selector); } return(await query.FirstOrDefaultAsync()); } }
public async Task <IEnumerable <T> > GetAsync(Expression <Func <T, bool> > filter = null, Expression <Func <T, T> > selector = null, int?page = null, int?size = null, Expression <Func <T, object> > include = null) { using (var db = new L2DBContext()) { IQueryable <T> query; if (include != null) { query = db.GetTable <T>().LoadWith(include); } else { query = db.GetTable <T>(); } if (filter != null) { query = query.Where(filter); } if (selector != null) { query = query.Select(selector); } if (page != null && size != null) { query = query.Take((page.Value - 1) * size.Value).Skip(size.Value); } return(await query.ToListAsync()); } }
public async Task <T> FindByIdAsync(int id) { using (var db = new L2DBContext()) { return(await db.GetTable <T>().Where(e => e.Id == id).FirstOrDefaultAsync()); } }
public IQueryable <T> GetQueryable() { var db = new L2DBContext(); return(db.GetTable <T>().AsQueryable()); }