Revisione modello dati + migration, bloccato invio dati al DB per revisione preliminare metodi
This commit is contained in:
@@ -31,7 +31,7 @@ namespace MP.Data.Repository.Utils
|
||||
.Where(x => x.Hour >= dtStart && x.Hour <= dtEnd);
|
||||
|
||||
if (!string.IsNullOrEmpty(sEnvir))
|
||||
query = query.Where(x => x.Envir == sEnvir);
|
||||
query = query.Where(x => x.Destination == sEnvir);
|
||||
|
||||
if (!string.IsNullOrEmpty(sType))
|
||||
query = query.Where(x => x.Type == sType);
|
||||
@@ -39,7 +39,7 @@ namespace MP.Data.Repository.Utils
|
||||
answ = await query
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Hour)
|
||||
.ThenBy(x => x.Envir)
|
||||
.ThenBy(x => x.Destination)
|
||||
.ThenBy(x => x.Type)
|
||||
.ToListAsync();
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace MP.Data.Repository.Utils
|
||||
var query = dbCtx.DbSetStatsDet.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(sEnvir))
|
||||
query = query.Where(x => x.Envir == sEnvir);
|
||||
query = query.Where(x => x.Destination == sEnvir);
|
||||
|
||||
if (!string.IsNullOrEmpty(sType))
|
||||
query = query.Where(x => x.Type == sType);
|
||||
@@ -105,22 +105,22 @@ namespace MP.Data.Repository.Utils
|
||||
// ora preparo inserimento massivo
|
||||
var existingRecords = await dbCtx
|
||||
.DbSetStatsDet
|
||||
.Where(x => listRecords.Select(r => new { r.Hour, r.Envir, r.Type }).Contains(new { Hour = x.Hour, Envir = x.Envir, Type = x.Type }))
|
||||
.Where(x => listRecords.Select(r => new { r.Hour, r.Destination, r.Type }).Contains(new { Hour = x.Hour, Destination = x.Destination, Type = x.Type }))
|
||||
.ToListAsync();
|
||||
|
||||
if (existingRecords.Count > 0)
|
||||
{
|
||||
var existingKeys = existingRecords.Select(r => new { r.Hour, r.Envir, r.Type }).ToHashSet();
|
||||
var existingKeys = existingRecords.Select(r => new { r.Hour, r.Destination, r.Type }).ToHashSet();
|
||||
|
||||
var recordsToUpdate = listRecords.Where(r =>
|
||||
existingKeys.Contains(new { Hour = r.Hour, Envir = r.Envir, Type = r.Type })).ToList();
|
||||
existingKeys.Contains(new { Hour = r.Hour, Destination = r.Destination, Type = r.Type })).ToList();
|
||||
|
||||
var recordsToAdd = listRecords.Where(r =>
|
||||
!existingKeys.Contains(new { Hour = r.Hour, Envir = r.Envir, Type = r.Type })).ToList();
|
||||
!existingKeys.Contains(new { Hour = r.Hour, Destination = r.Destination, Type = r.Type })).ToList();
|
||||
|
||||
foreach (var updateRec in recordsToUpdate)
|
||||
{
|
||||
var existing = Enumerable.First<StatsDetailModel>(existingRecords, (Func<StatsDetailModel, bool>)(x => x.Hour == updateRec.Hour && x.Envir == updateRec.Envir && x.Type == updateRec.Type));
|
||||
var existing = Enumerable.First<StatsDetailModel>((IEnumerable<StatsDetailModel>)existingRecords, (Func<StatsDetailModel, bool>)(x => x.Hour == updateRec.Hour && x.Destination == updateRec.Destination && x.Type == updateRec.Type));
|
||||
existing.RequestCount = updateRec.RequestCount;
|
||||
existing.AvgDuration = updateRec.AvgDuration;
|
||||
existing.MaxDuration = updateRec.MaxDuration;
|
||||
|
||||
Reference in New Issue
Block a user