Add DbContext Set method into interface

This commit is contained in:
Фролов 2021-08-09 14:39:56 +05:00
parent 0434ec4fd9
commit 9e69ff4ce7
2 changed files with 11 additions and 8 deletions

View File

@ -34,6 +34,10 @@ namespace AsbCloudDb.Model
int SaveChanges(bool acceptAllChangesOnSuccess);
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
DbSet<TEntity> Set<TEntity>(string name) where TEntity : class;
DbSet<TEntity> Set<TEntity>() where TEntity : class;
IQueryable<Well> GetWellsForCompany(int idCompany);
IQueryable<User> GetUsersByLogin(string login);
(DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate;

View File

@ -11,13 +11,12 @@ namespace AsbCloudInfrastructure.Services
where TModel : class, AsbCloudDb.Model.IId
where Tdto : AsbCloudApp.Data.IId
{
private readonly DbContext context;
private readonly IAsbCloudDbContext db;
private readonly IAsbCloudDbContext context;
private readonly DbSet<TModel> dbSet;
public CrudService(IAsbCloudDbContext db)
public CrudService(IAsbCloudDbContext context)
{
this.db = db;
this.context = context;
dbSet = context.Set<TModel>();
}
@ -44,7 +43,7 @@ namespace AsbCloudInfrastructure.Services
{
var newEntity = newItem.Adapt<TModel>();
var dbEntity = dbSet.Add(newEntity);
db.SaveChanges();
context.SaveChanges();
return dbEntity.Entity.Adapt<Tdto>();
}
@ -56,7 +55,7 @@ namespace AsbCloudInfrastructure.Services
for (int i = 0; i < dbEntities.Length; i++)
dbEntities[i] = dbSet.Add(newEntities.ElementAt(i));
db.SaveChanges();
context.SaveChanges();
return dbEntities.Select(e => e.Entity.Adapt<Tdto>());
}
@ -64,7 +63,7 @@ namespace AsbCloudInfrastructure.Services
{
var newEntity = item.Adapt<TModel>();
var dbEntity = dbSet.Update(newEntity);
db.SaveChanges();
context.SaveChanges();
return dbEntity.Entity.Adapt<Tdto>();
}
@ -74,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
if (entity == default)
return 0;
dbSet.Remove(entity);
return db.SaveChanges();
return context.SaveChanges();
}
}