public async Task <bool> DeleteAll(List <TEntity> entities) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); context.Set <TEntity>().RemoveRange(entities); await context.SaveChangesAsync(); return(true); }
public async Task <TEntity> Update(TEntity entity) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); context.Set <TEntity>().Update(entity); await context.SaveChangesAsync(); return(entity); }
public async Task <TEntity> Create(TEntity entity) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); var newEntry = await context.Set <TEntity>().AddAsync(entity); await context.SaveChangesAsync(); return(newEntry.Entity); }
public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate, Expression <Func <TEntity, object> >[] includes) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); IQueryable <TEntity> query = context.Set <TEntity>(); query = includes.Aggregate(query, (current, expression) => current.Include(expression)); return(query.Where(predicate).ToList()); }
public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(context.Set <TEntity>().Where(predicate).ToList()); }
public async Task <TEntity> FindOneBy(Expression <Func <TEntity, bool> > predicate) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().FirstOrDefaultAsync(predicate)); }
public async Task <TEntity> Find(TId id) { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().FindAsync(id)); }
public async Task <List <TEntity> > GetAll() { await using RecipeBookDbContext context = this._factory.CreateDbContext(); return(await context.Set <TEntity>().ToListAsync()); }