diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 2c8944a4..d4cff5da 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -227,7 +227,7 @@ namespace AsbCloudInfrastructure.Repository IdParent = parentRelationDictionary[g.Key].IdParent }); var defaultId = 0; - while (dtos.Any(x => x.IdParent != null)) + while (dtos.Any(x => x.IdParent == null)) { defaultId--; dtos = dtos @@ -235,12 +235,16 @@ namespace AsbCloudInfrastructure.Repository .Select(g => new WellGroupOpertionDto { IdCategory = g.Key ?? defaultId, - Category = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].Name : "unknown", + Category = g.Key.HasValue + ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.Name ?? "unknown" + : "unknown", Count = g.Sum(o => o.Count), DeltaDepth = g.Sum(o => o.DeltaDepth), TotalMinutes = g.Sum(o => o.TotalMinutes), Items = g.ToList(), - IdParent = g.Key.HasValue ? parentRelationDictionary[g.Key.Value].IdParent : defaultId, + IdParent = g.Key.HasValue + ? parentRelationDictionary.GetValueOrDefault(g.Key.Value)?.IdParent ?? defaultId + : defaultId, }); } return dtos;