From 910f838eece612f72a45060a3f1a9a553fb901e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 22 Apr 2024 14:16:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D1=8F.=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=93=D0=93?= =?UTF-8?q?=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/CrudRepositoryBase.cs | 16 ++++++++++------ AsbCloudInfrastructure/Services/WellService.cs | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) 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;