diff --git a/AsbCloudInfrastructure/Repository/CrudRepositoryBase.cs b/AsbCloudInfrastructure/Repository/CrudRepositoryBase.cs index 944dabd5..80bc3a99 100644 --- a/AsbCloudInfrastructure/Repository/CrudRepositoryBase.cs +++ b/AsbCloudInfrastructure/Repository/CrudRepositoryBase.cs @@ -133,18 +133,22 @@ namespace AsbCloudInfrastructure.Repository if (ids.Length != dtos.Count()) throw new ArgumentInvalidException(nameof(dtos), "Все записи должны иметь уникальные Id"); - var dbSet = dbContext.Set(); - - var existingEntitiesCount = await dbSet + var existingEntitiesCount = await dbContext.Set() .Where(o => ids.Contains(o.Id)) .CountAsync(token); if (ids.Length != existingEntitiesCount) throw new ArgumentInvalidException(nameof(dtos), "Все записи должны существовать в БД"); + + var entities = dtos.Select(Convert); - var entities = dbContext.Set().Where(e => ids.Contains(e.Id)); - dbContext.Set().UpdateRange(entities); - return await dbContext.SaveChangesAsync(token); + var entries = entities.Select(entity => dbContext.Set().Update(entity)).ToList(); + + var affected = await dbContext.SaveChangesAsync(token); + + entries.ForEach(entry => entry.State = EntityState.Detached); + + return affected; } /// diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 795d944b..a10ff824 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -274,6 +274,7 @@ namespace AsbCloudInfrastructure.Services dto.Timezone = GetTimezone(entity.Id); dto.StartDate = dbContext.WellOperations.Where(e => e.IdType == WellOperation.IdOperationTypeFact) + .AsNoTracking() .MinOrDefault(e => e.DateStart)?.ToRemoteDateTime(dto.Timezone.Hours); dto.WellType = entity.WellType.Caption; dto.Cluster = entity.Cluster.Caption;