public async Task DeleteByIdsAsync <T>(IEnumerable <Int32> ids) where T : class, IEntity { using (var context = new AppsEntities()) { var items = context.Set <T>().Where(e => ids.Contains(e.ID)); context.Set <T>().RemoveRange(items); await context.SaveChangesAsync(); } }
public IEnumerable <T> Get <T>() where T : class { using (var context = new AppsEntities()) { return(context.Set <T>().AsNoTracking().ToList()); } }
public async Task <T> GetSingleAsync <T>(Expression <Func <T, bool> > filter) where T : class, IEntity { using (var context = new AppsEntities()) { return(await context.Set <T>().FirstOrDefaultAsync(filter)); } }
public async Task <T> GetSingleAsync <T>(int id) where T : class, IEntity { using (var context = new AppsEntities()) { return(await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id)); } }
public T GetSingle <T>(int id) where T : class, IEntity { using (var context = new AppsEntities()) { return(context.Set <T>().FirstOrDefault(e => e.ID == id)); } }
public IEnumerable <T> GetFiltered <T>(Expression <Func <T, bool> > filter) where T : class { using (var context = new AppsEntities()) { return(context.Set <T>().AsNoTracking().Where(filter).ToList()); } }
public async Task SaveNewEntityRangeAsync <T>(IEnumerable <T> items) where T : class { using (var context = new AppsEntities()) { context.Set <T>().AddRange(items); await context.SaveChangesAsync(); } }
public void SaveNewEntityRange <T>(IEnumerable <T> items) where T : class { using (var context = new AppsEntities()) { context.Set <T>().AddRange(items); context.SaveChanges(); } }
public async Task SaveNewEntityAsync <T>(T item) where T : class { using (var context = new AppsEntities()) { context.Set <T>().Add(item); await context.SaveChangesAsync(); } }
public void SaveNewEntity <T>(T item) where T : class { using (var context = new AppsEntities()) { context.Set <T>().Add(item); context.SaveChanges(); } }
public Task <List <T> > GetFilteredAsync <T>(Expression <Func <T, bool> > filter) where T : class { using (var context = new AppsEntities()) { var set = context.Set <T>().AsQueryable(); return(set.AsNoTracking().Where(filter).ToListAsync()); } }
public async Task DeleteScreenshotsById(IEnumerable <Int32> ids) { using (var context = new AppsEntities()) { var screenshots = await context.Set <Screenshot>().Where(s => ids.Contains(s.ID)).ToListAsync(); context.Screenshots.RemoveRange(screenshots); await context.SaveChangesAsync(); } }
public Task <List <T> > GetAsync <T>(params Expression <Func <T, object> >[] navigations) where T : class { using (var context = new AppsEntities()) { IQueryable <T> query = context.Set <T>().AsQueryable(); foreach (var nav in navigations) { query = query.Include(nav); } return(query.AsNoTracking().ToListAsync <T>()); } }
public IEnumerable <T> GetFiltered <T>(Expression <Func <T, bool> > filter, params Expression <Func <T, object> >[] navigations) where T : class { using (var context = new AppsEntities()) { var query = context.Set <T>().AsQueryable(); foreach (var nav in navigations) { query = query.Include(nav); } return(query.AsNoTracking().Where(filter).ToList()); } }
public IEnumerable <T> GetOrderedDesc <T, TKey>(Expression <Func <T, bool> > filter, Expression <Func <T, TKey> > selector, int count) where T : class { using (var context = new AppsEntities()) { return(context.Set <T>() .AsNoTracking() .Where(filter) .OrderByDescending(selector) .Take(count) .ToList()); } }