// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Geometry; using Core.Common.Utils; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Piping.Data; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Create { /// /// This class can be used to keep track of create and update operations on a database. /// This information can be used to reuse objects. When all operations have been performed, /// then the collected information can be used to transfer the ids assigned to the created /// database instances back to the data model or to clean up orphans. /// internal class PersistenceRegistry { private readonly Dictionary projects = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary assessmentSections = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary failureMechanisms = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary failureMechanismSections = new Dictionary(); private readonly Dictionary pipingFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary generalGrassCoverErosionInwardsInputs = new Dictionary(); private readonly Dictionary dikeProfiles = new Dictionary(); private readonly Dictionary grassCoverErosionInwardsCalculations = new Dictionary(); private readonly Dictionary grassCoverErosionInwardsOutputs = new Dictionary(); private readonly Dictionary grassCoverErosionInwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary heightStructuresFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary strengthStabilityLengthwiseConstructionFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary technicalInnovationFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary waterPressureAsphaltCoverFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary closingStructureFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary macrostabilityInwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary macrostabilityOutwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary waveImpactAsphaltCoverFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary grassCoverErosionOutwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary grassCoverSlipOffInwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary grassCoverSlipOffOutwardsFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary microstabilityFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary pipingStructureFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary duneErosionFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary stabilityStoneCoverFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary strengthStabilityPointConstructionFailureMechanismSectionResults = new Dictionary(); private readonly Dictionary hydraulicLocations = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary calculationGroups = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary pipingCalculations = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary pipingOutputs = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary pipingSemiProbabilisticOutputs = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary stochasticSoilModels = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary stochasticSoilProfiles = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary soilProfiles = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary soilLayers = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary surfaceLines = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary surfaceLinePoints = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary characteristicPoints = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary pipingProbabilityAssessmentInputs = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary probabilisticAssessmentOutputs = new Dictionary(new ReferenceEqualityComparer()); /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(FailureMechanismSectionEntity entity, FailureMechanismSection model) { Register(failureMechanismSections, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingSectionResultEntity entity, PipingFailureMechanismSectionResult model) { Register(pipingFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(GrassCoverErosionInwardsFailureMechanismMetaEntity entity, GeneralGrassCoverErosionInwardsInput model) { Register(generalGrassCoverErosionInwardsInputs, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(DikeProfileEntity entity, DikeProfile model) { Register(dikeProfiles, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The /// to be registered. /// The to /// be registered. /// Thrown when either: /// /// is null /// is null /// public void Register(GrassCoverErosionInwardsCalculationEntity entity, GrassCoverErosionInwardsCalculation model) { Register(grassCoverErosionInwardsCalculations, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The /// to be registered. /// The to /// be registered. /// Thrown when either: /// /// is null /// is null /// public void Register(GrassCoverErosionInwardsOutputEntity entity, GrassCoverErosionInwardsOutput model) { Register(grassCoverErosionInwardsOutputs, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The /// to be registered. /// The to /// be registered. /// Thrown when either: /// /// is null /// is null /// public void Register(ProbabilisticOutputEntity entity, ProbabilityAssessmentOutput model) { Register(probabilisticAssessmentOutputs, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(GrassCoverErosionInwardsSectionResultEntity entity, GrassCoverErosionInwardsFailureMechanismSectionResult model) { Register(grassCoverErosionInwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(HeightStructuresSectionResultEntity entity, HeightStructuresFailureMechanismSectionResult model) { Register(heightStructuresFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(StrengthStabilityLengthwiseConstructionSectionResultEntity entity, StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult model) { Register(strengthStabilityLengthwiseConstructionFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(TechnicalInnovationSectionResultEntity entity, TechnicalInnovationFailureMechanismSectionResult model) { Register(technicalInnovationFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(WaterPressureAsphaltCoverSectionResultEntity entity, WaterPressureAsphaltCoverFailureMechanismSectionResult model) { Register(waterPressureAsphaltCoverFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(ClosingStructureSectionResultEntity entity, ClosingStructureFailureMechanismSectionResult model) { Register(closingStructureFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(MacrostabilityInwardsSectionResultEntity entity, MacrostabilityInwardsFailureMechanismSectionResult model) { Register(macrostabilityInwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(MacrostabilityOutwardsSectionResultEntity entity, MacrostabilityOutwardsFailureMechanismSectionResult model) { Register(macrostabilityOutwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(WaveImpactAsphaltCoverSectionResultEntity entity, WaveImpactAsphaltCoverFailureMechanismSectionResult model) { Register(waveImpactAsphaltCoverFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(GrassCoverErosionOutwardsSectionResultEntity entity, GrassCoverErosionOutwardsFailureMechanismSectionResult model) { Register(grassCoverErosionOutwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(GrassCoverSlipOffInwardsSectionResultEntity entity, GrassCoverSlipOffInwardsFailureMechanismSectionResult model) { Register(grassCoverSlipOffInwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(GrassCoverSlipOffOutwardsSectionResultEntity entity, GrassCoverSlipOffOutwardsFailureMechanismSectionResult model) { Register(grassCoverSlipOffOutwardsFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(MicrostabilitySectionResultEntity entity, MicrostabilityFailureMechanismSectionResult model) { Register(microstabilityFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingStructureSectionResultEntity entity, PipingStructureFailureMechanismSectionResult model) { Register(pipingStructureFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(DuneErosionSectionResultEntity entity, DuneErosionFailureMechanismSectionResult model) { Register(duneErosionFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(StabilityStoneCoverSectionResultEntity entity, StabilityStoneCoverFailureMechanismSectionResult model) { Register(stabilityStoneCoverFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(StrengthStabilityPointConstructionSectionResultEntity entity, StrengthStabilityPointConstructionFailureMechanismSectionResult model) { Register(strengthStabilityPointConstructionFailureMechanismSectionResults, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(CalculationGroupEntity entity, CalculationGroup model) { Register(calculationGroups, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingCalculationEntity entity, PipingCalculationScenario model) { Register(pipingCalculations, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingCalculationOutputEntity entity, PipingOutput model) { Register(pipingOutputs, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingSemiProbabilisticOutputEntity entity, PipingSemiProbabilisticOutput model) { Register(pipingSemiProbabilisticOutputs, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(ProjectEntity entity, RingtoetsProject model) { Register(projects, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(AssessmentSectionEntity entity, AssessmentSection model) { Register(assessmentSections, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) { Register(hydraulicLocations, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(FailureMechanismEntity entity, IFailureMechanism model) { Register(failureMechanisms, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(StochasticSoilModelEntity entity, StochasticSoilModel model) { Register(stochasticSoilModels, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(StochasticSoilProfileEntity entity, StochasticSoilProfile model) { Register(stochasticSoilProfiles, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(SoilProfileEntity entity, PipingSoilProfile model) { Register(soilProfiles, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(SoilLayerEntity entity, PipingSoilLayer model) { Register(soilLayers, entity, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(StochasticSoilModel model) { return ContainsValue(stochasticSoilModels, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(StochasticSoilProfile model) { return ContainsValue(stochasticSoilProfiles, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(PipingSoilProfile model) { return ContainsValue(soilProfiles, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(HydraulicBoundaryLocation model) { return ContainsValue(hydraulicLocations, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(RingtoetsPipingSurfaceLine model) { return ContainsValue(surfaceLines, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(FailureMechanismSection model) { return ContainsValue(failureMechanismSections, model); } /// /// Checks whether a create or update operations has been registered for the given /// . /// /// The to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. internal bool Contains(DikeProfile model) { return ContainsValue(dikeProfiles, model); } /// /// Obtains the which was registered for /// the given . /// /// The for which a create/update /// operation has been registered. /// The created . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out whether /// a create/update operation has been registered for . internal StochasticSoilModelEntity Get(StochasticSoilModel model) { return Get(stochasticSoilModels, model); } /// /// Obtains the which was registered for /// the given . /// /// The for which a create/update /// operation has been registered. /// The created . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out whether /// a create/create operation has been registered for . internal StochasticSoilProfileEntity Get(StochasticSoilProfile model) { return Get(stochasticSoilProfiles, model); } /// /// Obtains the which was registered for the given /// . /// /// The for which a create/update /// operation has been registered. /// The constructed . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out whether a /// create/update operation has been registered for . internal SoilProfileEntity Get(PipingSoilProfile model) { return Get(soilProfiles, model); } /// /// Obtains the which was registered for the given /// . /// /// The for which a /// read/update operation has been registered. /// The constructed . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out /// whether a create/update operation has been registered for . internal SurfaceLineEntity Get(RingtoetsPipingSurfaceLine model) { return Get(surfaceLines, model); } /// /// Obtains the which was registered for the /// given . /// /// The for which a /// read/update operation has been registered. /// The constructed . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out /// whether a create/update operation has been registered for . internal HydraulicLocationEntity Get(HydraulicBoundaryLocation model) { return Get(hydraulicLocations, model); } /// /// Obtains the which was registered for the /// given . /// /// The for which a /// read/update operation has been registered. /// The constructed . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out /// whether a create/update operation has been registered for . internal FailureMechanismSectionEntity Get(FailureMechanismSection model) { return Get(failureMechanismSections, model); } /// /// Obtains the which was registered for the /// given . /// /// The for which a /// read/update operation has been registered. /// The constructed . /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . /// Use to find out /// whether a create/update operation has been registered for . internal DikeProfileEntity Get(DikeProfile model) { return Get(dikeProfiles, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(SurfaceLineEntity entity, RingtoetsPipingSurfaceLine model) { Register(surfaceLines, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The surfaceline geometry to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(SurfaceLinePointEntity entity, Point3D model) { Register(surfaceLinePoints, entity, model); } /// /// Obtains the which was registered for the /// given . /// /// The surfaceline geometry for which /// a create or update operation has been registered. /// Thrown when is null. /// Thrown when no create/update operation /// has been registered for . internal SurfaceLinePointEntity GetSurfaceLinePoint(Point3D model) { return Get(surfaceLinePoints, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The surfaceline geometry corresponding /// to the characteristic point data to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(CharacteristicPointEntity entity, Point3D model) { Register(characteristicPoints, entity, model); } /// /// Registers a create or update operation for and the /// that was constructed with the information. /// /// The to be registered. /// The to be registered. /// Thrown when either: /// /// is null /// is null /// internal void Register(PipingFailureMechanismMetaEntity entity, PipingProbabilityAssessmentInput model) { Register(pipingProbabilityAssessmentInputs, entity, model); } /// /// Transfer ids from the created entities to the domain model objects' property. /// internal void TransferIds() { foreach (var entity in projects.Keys) { projects[entity].StorageId = entity.ProjectEntityId; } foreach (var entity in failureMechanisms.Keys) { failureMechanisms[entity].StorageId = entity.FailureMechanismEntityId; } foreach (var entity in failureMechanismSections.Keys) { failureMechanismSections[entity].StorageId = entity.FailureMechanismSectionEntityId; } foreach (var entity in assessmentSections.Keys) { assessmentSections[entity].StorageId = entity.AssessmentSectionEntityId; } foreach (var entity in pipingFailureMechanismSectionResults.Keys) { pipingFailureMechanismSectionResults[entity].StorageId = entity.PipingSectionResultEntityId; } foreach (var entity in generalGrassCoverErosionInwardsInputs.Keys) { generalGrassCoverErosionInwardsInputs[entity].StorageId = entity.GrassCoverErosionInwardsFailureMechanismMetaEntityId; } foreach (var entity in dikeProfiles.Keys) { dikeProfiles[entity].StorageId = entity.DikeProfileEntityId; } foreach (var entity in grassCoverErosionInwardsCalculations.Keys) { grassCoverErosionInwardsCalculations[entity].StorageId = entity.GrassCoverErosionInwardsCalculationEntityId; } foreach (var entity in grassCoverErosionInwardsOutputs.Keys) { grassCoverErosionInwardsOutputs[entity].StorageId = entity.GrassCoverErosionInwardsOutputId; } foreach (var entity in grassCoverErosionInwardsFailureMechanismSectionResults.Keys) { grassCoverErosionInwardsFailureMechanismSectionResults[entity].StorageId = entity.GrassCoverErosionInwardsSectionResultEntityId; } foreach (var entity in heightStructuresFailureMechanismSectionResults.Keys) { heightStructuresFailureMechanismSectionResults[entity].StorageId = entity.HeightStructuresSectionResultEntityId; } foreach (var entity in strengthStabilityLengthwiseConstructionFailureMechanismSectionResults.Keys) { strengthStabilityLengthwiseConstructionFailureMechanismSectionResults[entity].StorageId = entity.StrengthStabilityLengthwiseConstructionSectionResultEntityId; } foreach (var entity in technicalInnovationFailureMechanismSectionResults.Keys) { technicalInnovationFailureMechanismSectionResults[entity].StorageId = entity.TechnicalInnovationSectionResultEntityId; } foreach (var entity in waterPressureAsphaltCoverFailureMechanismSectionResults.Keys) { waterPressureAsphaltCoverFailureMechanismSectionResults[entity].StorageId = entity.WaterPressureAsphaltCoverSectionResultEntityId; } foreach (var entity in closingStructureFailureMechanismSectionResults.Keys) { closingStructureFailureMechanismSectionResults[entity].StorageId = entity.ClosingStructureSectionResultEntityId; } foreach (var entity in macrostabilityInwardsFailureMechanismSectionResults.Keys) { macrostabilityInwardsFailureMechanismSectionResults[entity].StorageId = entity.MacrostabilityInwardsSectionResultEntityId; } foreach (var entity in macrostabilityOutwardsFailureMechanismSectionResults.Keys) { macrostabilityOutwardsFailureMechanismSectionResults[entity].StorageId = entity.MacrostabilityOutwardsSectionResultEntityId; } foreach (var entity in waveImpactAsphaltCoverFailureMechanismSectionResults.Keys) { waveImpactAsphaltCoverFailureMechanismSectionResults[entity].StorageId = entity.WaveImpactAsphaltCoverSectionResultEntityId; } foreach (var entity in grassCoverErosionOutwardsFailureMechanismSectionResults.Keys) { grassCoverErosionOutwardsFailureMechanismSectionResults[entity].StorageId = entity.GrassCoverErosionOutwardsSectionResultEntityId; } foreach (var entity in grassCoverSlipOffInwardsFailureMechanismSectionResults.Keys) { grassCoverSlipOffInwardsFailureMechanismSectionResults[entity].StorageId = entity.GrassCoverSlipOffInwardsSectionResultEntityId; } foreach (var entity in grassCoverSlipOffOutwardsFailureMechanismSectionResults.Keys) { grassCoverSlipOffOutwardsFailureMechanismSectionResults[entity].StorageId = entity.GrassCoverSlipOffOutwardsSectionResultEntityId; } foreach (var entity in microstabilityFailureMechanismSectionResults.Keys) { microstabilityFailureMechanismSectionResults[entity].StorageId = entity.MicrostabilitySectionResultEntityId; } foreach (var entity in pipingStructureFailureMechanismSectionResults.Keys) { pipingStructureFailureMechanismSectionResults[entity].StorageId = entity.PipingStructureSectionResultEntityId; } foreach (var entity in duneErosionFailureMechanismSectionResults.Keys) { duneErosionFailureMechanismSectionResults[entity].StorageId = entity.DuneErosionSectionResultEntityId; } foreach (var entity in stabilityStoneCoverFailureMechanismSectionResults.Keys) { stabilityStoneCoverFailureMechanismSectionResults[entity].StorageId = entity.StabilityStoneCoverSectionResultEntityId; } foreach (var entity in strengthStabilityPointConstructionFailureMechanismSectionResults.Keys) { strengthStabilityPointConstructionFailureMechanismSectionResults[entity].StorageId = entity.StrengthStabilityPointConstructionSectionResultEntityId; } foreach (var entity in hydraulicLocations.Keys) { hydraulicLocations[entity].StorageId = entity.HydraulicLocationEntityId; } foreach (var entity in calculationGroups.Keys) { calculationGroups[entity].StorageId = entity.CalculationGroupEntityId; } foreach (var entity in pipingCalculations.Keys) { pipingCalculations[entity].StorageId = entity.PipingCalculationEntityId; } foreach (var entity in pipingOutputs.Keys) { pipingOutputs[entity].StorageId = entity.PipingCalculationOutputEntityId; } foreach (var entity in pipingSemiProbabilisticOutputs.Keys) { pipingSemiProbabilisticOutputs[entity].StorageId = entity.PipingSemiProbabilisticOutputEntityId; } foreach (var entity in stochasticSoilModels.Keys) { stochasticSoilModels[entity].StorageId = entity.StochasticSoilModelEntityId; } foreach (var entity in stochasticSoilProfiles.Keys) { stochasticSoilProfiles[entity].StorageId = entity.StochasticSoilProfileEntityId; } foreach (var entity in soilProfiles.Keys) { soilProfiles[entity].StorageId = entity.SoilProfileEntityId; } foreach (var entity in soilLayers.Keys) { soilLayers[entity].StorageId = entity.SoilLayerEntityId; } foreach (var entity in surfaceLines.Keys) { surfaceLines[entity].StorageId = entity.SurfaceLineEntityId; } foreach (var entity in surfaceLinePoints.Keys) { surfaceLinePoints[entity].StorageId = entity.SurfaceLinePointEntityId; } foreach (var entity in pipingProbabilityAssessmentInputs.Keys) { pipingProbabilityAssessmentInputs[entity].StorageId = entity.PipingFailureMechanismMetaEntityId; } foreach (var entity in probabilisticAssessmentOutputs.Keys) { probabilisticAssessmentOutputs[entity].StorageId = entity.ProbabilisticOutputEntityId; } // CharacteristicPoints do not really have a 'identity' within the object-model. // As such, no need to copy StorageId. This is already covered by surfaceLinePoints. } /// /// Removes all the entities for which no update operation was registered from the . /// /// The from which to remove the entities. internal void RemoveUntouched(IRingtoetsEntities dbContext) { var orphanedProjectEntities = new List(); foreach (ProjectEntity projectEntity in dbContext.ProjectEntities .Where(e => e.ProjectEntityId > 0)) { if (!projects.ContainsKey(projectEntity)) { orphanedProjectEntities.Add(projectEntity); } } dbContext.ProjectEntities.RemoveRange(orphanedProjectEntities); var orphanedAssessmentSectionEntities = new List(); foreach (AssessmentSectionEntity assessmentSectionEntity in dbContext.AssessmentSectionEntities .Where(e => e.AssessmentSectionEntityId > 0)) { if (!assessmentSections.ContainsKey(assessmentSectionEntity)) { orphanedAssessmentSectionEntities.Add(assessmentSectionEntity); } } dbContext.AssessmentSectionEntities.RemoveRange(orphanedAssessmentSectionEntities); var orphanedFailureMechanismEntities = new List(); foreach (FailureMechanismEntity failureMechanismEntity in dbContext.FailureMechanismEntities .Where(e => e.FailureMechanismEntityId > 0)) { if (!failureMechanisms.ContainsKey(failureMechanismEntity)) { orphanedFailureMechanismEntities.Add(failureMechanismEntity); } } dbContext.FailureMechanismEntities.RemoveRange(orphanedFailureMechanismEntities); var orphanedFailureMechanismSectionEntities = new List(); foreach (FailureMechanismSectionEntity failureMechanismSectionEntity in dbContext.FailureMechanismSectionEntities .Where(e => e.FailureMechanismSectionEntityId > 0)) { if (!failureMechanismSections.ContainsKey(failureMechanismSectionEntity)) { orphanedFailureMechanismSectionEntities.Add(failureMechanismSectionEntity); } } dbContext.FailureMechanismSectionEntities.RemoveRange(orphanedFailureMechanismSectionEntities); var orphanedPipingSectionResultEntities = new List(); foreach (PipingSectionResultEntity pipingSectionResultEntity in dbContext.PipingSectionResultEntities .Where(e => e.PipingSectionResultEntityId > 0)) { if (!pipingFailureMechanismSectionResults.ContainsKey(pipingSectionResultEntity)) { orphanedPipingSectionResultEntities.Add(pipingSectionResultEntity); } } dbContext.PipingSectionResultEntities.RemoveRange(orphanedPipingSectionResultEntities); var orphanedGrassCoverErosionInwardsFailureMechanismMetaEntities = new List(); foreach (GrassCoverErosionInwardsFailureMechanismMetaEntity inputEntity in dbContext.GrassCoverErosionInwardsFailureMechanismMetaEntities .Where(e => e.GrassCoverErosionInwardsFailureMechanismMetaEntityId > 0)) { if (!generalGrassCoverErosionInwardsInputs.ContainsKey(inputEntity)) { orphanedGrassCoverErosionInwardsFailureMechanismMetaEntities.Add(inputEntity); } } dbContext.GrassCoverErosionInwardsFailureMechanismMetaEntities.RemoveRange(orphanedGrassCoverErosionInwardsFailureMechanismMetaEntities); var orphanedDikeProfileEntities = new List(); foreach (DikeProfileEntity dikeProfileEntity in dbContext.DikeProfileEntities .Where(e => e.DikeProfileEntityId > 0)) { if (!dikeProfiles.ContainsKey(dikeProfileEntity)) { orphanedDikeProfileEntities.Add(dikeProfileEntity); } } dbContext.DikeProfileEntities.RemoveRange(orphanedDikeProfileEntities); var orphanedGrassCoverErosionInwardsCalculationEntities = new List(); foreach (GrassCoverErosionInwardsCalculationEntity calculationEntity in dbContext.GrassCoverErosionInwardsCalculationEntities .Where(e => e.GrassCoverErosionInwardsCalculationEntityId > 0)) { if (!grassCoverErosionInwardsCalculations.ContainsKey(calculationEntity)) { orphanedGrassCoverErosionInwardsCalculationEntities.Add(calculationEntity); } } dbContext.GrassCoverErosionInwardsCalculationEntities.RemoveRange(orphanedGrassCoverErosionInwardsCalculationEntities); var orphanedGrassCoverErosionInwardsOutputEntities = new List(); foreach (GrassCoverErosionInwardsOutputEntity outputEntity in dbContext.GrassCoverErosionInwardsOutputEntities .Where(e => e.GrassCoverErosionInwardsOutputId > 0)) { if (!grassCoverErosionInwardsOutputs.ContainsKey(outputEntity)) { orphanedGrassCoverErosionInwardsOutputEntities.Add(outputEntity); } } dbContext.GrassCoverErosionInwardsOutputEntities.RemoveRange(orphanedGrassCoverErosionInwardsOutputEntities); var orphanedGrassCoverErosionInwardsSectionResultEntities = new List(); foreach (GrassCoverErosionInwardsSectionResultEntity sectionResultEntity in dbContext.GrassCoverErosionInwardsSectionResultEntities .Where(e => e.GrassCoverErosionInwardsSectionResultEntityId > 0)) { if (!grassCoverErosionInwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedGrassCoverErosionInwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.GrassCoverErosionInwardsSectionResultEntities.RemoveRange(orphanedGrassCoverErosionInwardsSectionResultEntities); var orphanedHeightStructuresSectionResultEntities = new List(); foreach (HeightStructuresSectionResultEntity sectionResultEntity in dbContext.HeightStructuresSectionResultEntities .Where(e => e.HeightStructuresSectionResultEntityId > 0)) { if (!heightStructuresFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedHeightStructuresSectionResultEntities.Add(sectionResultEntity); } } dbContext.HeightStructuresSectionResultEntities.RemoveRange(orphanedHeightStructuresSectionResultEntities); var orphanedStrengthStabilityLengthwiseConstructionSectionResultEntities = new List(); foreach (StrengthStabilityLengthwiseConstructionSectionResultEntity sectionResultEntity in dbContext.StrengthStabilityLengthwiseConstructionSectionResultEntities .Where(e => e.StrengthStabilityLengthwiseConstructionSectionResultEntityId > 0)) { if (!strengthStabilityLengthwiseConstructionFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedStrengthStabilityLengthwiseConstructionSectionResultEntities.Add(sectionResultEntity); } } dbContext.StrengthStabilityLengthwiseConstructionSectionResultEntities.RemoveRange(orphanedStrengthStabilityLengthwiseConstructionSectionResultEntities); var orphanedTechnicalInnovationSectionResultEntities = new List(); foreach (TechnicalInnovationSectionResultEntity sectionResultEntity in dbContext.TechnicalInnovationSectionResultEntities .Where(e => e.TechnicalInnovationSectionResultEntityId > 0)) { if (!technicalInnovationFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedTechnicalInnovationSectionResultEntities.Add(sectionResultEntity); } } dbContext.TechnicalInnovationSectionResultEntities.RemoveRange(orphanedTechnicalInnovationSectionResultEntities); var orphanedWaterPressureAsphaltCoverSectionResultEntities = new List(); foreach (WaterPressureAsphaltCoverSectionResultEntity sectionResultEntity in dbContext.WaterPressureAsphaltCoverSectionResultEntities .Where(e => e.WaterPressureAsphaltCoverSectionResultEntityId > 0)) { if (!waterPressureAsphaltCoverFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedWaterPressureAsphaltCoverSectionResultEntities.Add(sectionResultEntity); } } dbContext.WaterPressureAsphaltCoverSectionResultEntities.RemoveRange(orphanedWaterPressureAsphaltCoverSectionResultEntities); var orphanedClosingStructureSectionResultEntities = new List(); foreach (ClosingStructureSectionResultEntity sectionResultEntity in dbContext.ClosingStructureSectionResultEntities .Where(e => e.ClosingStructureSectionResultEntityId > 0)) { if (!closingStructureFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedClosingStructureSectionResultEntities.Add(sectionResultEntity); } } dbContext.ClosingStructureSectionResultEntities.RemoveRange(orphanedClosingStructureSectionResultEntities); var orphanedMacrostabilityInwardsSectionResultEntities = new List(); foreach (MacrostabilityInwardsSectionResultEntity sectionResultEntity in dbContext.MacrostabilityInwardsSectionResultEntities .Where(e => e.MacrostabilityInwardsSectionResultEntityId > 0)) { if (!macrostabilityInwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedMacrostabilityInwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.MacrostabilityInwardsSectionResultEntities.RemoveRange(orphanedMacrostabilityInwardsSectionResultEntities); var orphanedMacrostabilityOutwardsSectionResultEntities = new List(); foreach (MacrostabilityOutwardsSectionResultEntity sectionResultEntity in dbContext.MacrostabilityOutwardsSectionResultEntities .Where(e => e.MacrostabilityOutwardsSectionResultEntityId > 0)) { if (!macrostabilityOutwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedMacrostabilityOutwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.MacrostabilityOutwardsSectionResultEntities.RemoveRange(orphanedMacrostabilityOutwardsSectionResultEntities); var orphanedWaveImpactAsphaltCoverSectionResultEntities = new List(); foreach (WaveImpactAsphaltCoverSectionResultEntity sectionResultEntity in dbContext.WaveImpactAsphaltCoverSectionResultEntities .Where(e => e.WaveImpactAsphaltCoverSectionResultEntityId > 0)) { if (!waveImpactAsphaltCoverFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedWaveImpactAsphaltCoverSectionResultEntities.Add(sectionResultEntity); } } dbContext.WaveImpactAsphaltCoverSectionResultEntities.RemoveRange(orphanedWaveImpactAsphaltCoverSectionResultEntities); var orphanedGrassCoverErosionOutwardsSectionResultEntities = new List(); foreach (GrassCoverErosionOutwardsSectionResultEntity sectionResultEntity in dbContext.GrassCoverErosionOutwardsSectionResultEntities .Where(e => e.GrassCoverErosionOutwardsSectionResultEntityId > 0)) { if (!grassCoverErosionOutwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedGrassCoverErosionOutwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.GrassCoverErosionOutwardsSectionResultEntities.RemoveRange(orphanedGrassCoverErosionOutwardsSectionResultEntities); var orphanedGrassCoverSlipOffInwardsSectionResultEntities = new List(); foreach (GrassCoverSlipOffInwardsSectionResultEntity sectionResultEntity in dbContext.GrassCoverSlipOffInwardsSectionResultEntities .Where(e => e.GrassCoverSlipOffInwardsSectionResultEntityId > 0)) { if (!grassCoverSlipOffInwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedGrassCoverSlipOffInwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.GrassCoverSlipOffInwardsSectionResultEntities.RemoveRange(orphanedGrassCoverSlipOffInwardsSectionResultEntities); var orphanedGrassCoverSlipOffOutwardsSectionResultEntities = new List(); foreach (GrassCoverSlipOffOutwardsSectionResultEntity sectionResultEntity in dbContext.GrassCoverSlipOffOutwardsSectionResultEntities .Where(e => e.GrassCoverSlipOffOutwardsSectionResultEntityId > 0)) { if (!grassCoverSlipOffOutwardsFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedGrassCoverSlipOffOutwardsSectionResultEntities.Add(sectionResultEntity); } } dbContext.GrassCoverSlipOffOutwardsSectionResultEntities.RemoveRange(orphanedGrassCoverSlipOffOutwardsSectionResultEntities); var orphanedMicrostabilitySectionResultEntities = new List(); foreach (MicrostabilitySectionResultEntity sectionResultEntity in dbContext.MicrostabilitySectionResultEntities .Where(e => e.MicrostabilitySectionResultEntityId > 0)) { if (!microstabilityFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedMicrostabilitySectionResultEntities.Add(sectionResultEntity); } } dbContext.MicrostabilitySectionResultEntities.RemoveRange(orphanedMicrostabilitySectionResultEntities); var orphanedPipingStructureSectionResultEntities = new List(); foreach (PipingStructureSectionResultEntity sectionResultEntity in dbContext.PipingStructureSectionResultEntities .Where(e => e.PipingStructureSectionResultEntityId > 0)) { if (!pipingStructureFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedPipingStructureSectionResultEntities.Add(sectionResultEntity); } } dbContext.PipingStructureSectionResultEntities.RemoveRange(orphanedPipingStructureSectionResultEntities); var orphanedDuneErosionSectionResultEntities = new List(); foreach (DuneErosionSectionResultEntity sectionResultEntity in dbContext.DuneErosionSectionResultEntities .Where(e => e.DuneErosionSectionResultEntityId > 0)) { if (!duneErosionFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedDuneErosionSectionResultEntities.Add(sectionResultEntity); } } dbContext.DuneErosionSectionResultEntities.RemoveRange(orphanedDuneErosionSectionResultEntities); var orphanedStabilityStoneCoverSectionResultEntities = new List(); foreach (StabilityStoneCoverSectionResultEntity sectionResultEntity in dbContext.StabilityStoneCoverSectionResultEntities .Where(e => e.StabilityStoneCoverSectionResultEntityId > 0)) { if (!stabilityStoneCoverFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedStabilityStoneCoverSectionResultEntities.Add(sectionResultEntity); } } dbContext.StabilityStoneCoverSectionResultEntities.RemoveRange(orphanedStabilityStoneCoverSectionResultEntities); var orphanedStrengthStabilityPointConstructionSectionResultEntities = new List(); foreach (StrengthStabilityPointConstructionSectionResultEntity sectionResultEntity in dbContext.StrengthStabilityPointConstructionSectionResultEntities .Where(e => e.StrengthStabilityPointConstructionSectionResultEntityId > 0)) { if (!strengthStabilityPointConstructionFailureMechanismSectionResults.ContainsKey(sectionResultEntity)) { orphanedStrengthStabilityPointConstructionSectionResultEntities.Add(sectionResultEntity); } } dbContext.StrengthStabilityPointConstructionSectionResultEntities.RemoveRange(orphanedStrengthStabilityPointConstructionSectionResultEntities); var orphanedHydraulicLocationEntities = new List(); foreach (HydraulicLocationEntity hydraulicLocationEntity in dbContext.HydraulicLocationEntities .Where(e => e.HydraulicLocationEntityId > 0)) { if (!hydraulicLocations.ContainsKey(hydraulicLocationEntity)) { orphanedHydraulicLocationEntities.Add(hydraulicLocationEntity); } } dbContext.HydraulicLocationEntities.RemoveRange(orphanedHydraulicLocationEntities); var orphanedCalculationGroupEntities = new List(); foreach (CalculationGroupEntity calculationGroupEntity in dbContext.CalculationGroupEntities .Where(e => e.CalculationGroupEntityId > 0)) { if (!calculationGroups.ContainsKey(calculationGroupEntity)) { orphanedCalculationGroupEntities.Add(calculationGroupEntity); } } dbContext.CalculationGroupEntities.RemoveRange(orphanedCalculationGroupEntities); var orphanedPipingCalculationEntities = new List(); foreach (PipingCalculationEntity pipingCalculationEntity in dbContext.PipingCalculationEntities .Where(e => e.PipingCalculationEntityId > 0)) { if (!pipingCalculations.ContainsKey(pipingCalculationEntity)) { orphanedPipingCalculationEntities.Add(pipingCalculationEntity); } } dbContext.PipingCalculationEntities.RemoveRange(orphanedPipingCalculationEntities); var orphanedPipingCalculationOutputEntities = new List(); foreach (PipingCalculationOutputEntity pipingCalculationOutputEntity in dbContext.PipingCalculationOutputEntities .Where(e => e.PipingCalculationOutputEntityId > 0)) { if (!pipingOutputs.ContainsKey(pipingCalculationOutputEntity)) { orphanedPipingCalculationOutputEntities.Add(pipingCalculationOutputEntity); } } dbContext.PipingCalculationOutputEntities.RemoveRange(orphanedPipingCalculationOutputEntities); var orphanedPipingSemiProbabilisticOutputEntities = new List(); foreach (PipingSemiProbabilisticOutputEntity pipingSemiProbabilisticOutputEntity in dbContext.PipingSemiProbabilisticOutputEntities .Where(e => e.PipingSemiProbabilisticOutputEntityId > 0)) { if (!pipingSemiProbabilisticOutputs.ContainsKey(pipingSemiProbabilisticOutputEntity)) { orphanedPipingSemiProbabilisticOutputEntities.Add(pipingSemiProbabilisticOutputEntity); } } dbContext.PipingSemiProbabilisticOutputEntities.RemoveRange(orphanedPipingSemiProbabilisticOutputEntities); var orphanedStochasticSoilModelEntities = new List(); foreach (StochasticSoilModelEntity stochasticSoilModelEntity in dbContext.StochasticSoilModelEntities .Where(e => e.StochasticSoilModelEntityId > 0)) { if (!stochasticSoilModels.ContainsKey(stochasticSoilModelEntity)) { orphanedStochasticSoilModelEntities.Add(stochasticSoilModelEntity); } } dbContext.StochasticSoilModelEntities.RemoveRange(orphanedStochasticSoilModelEntities); var orphanedStochasticSoilProfileEntities = new List(); foreach (StochasticSoilProfileEntity stochasticSoilProfileEntity in dbContext.StochasticSoilProfileEntities .Where(e => e.StochasticSoilProfileEntityId > 0)) { if (!stochasticSoilProfiles.ContainsKey(stochasticSoilProfileEntity)) { orphanedStochasticSoilProfileEntities.Add(stochasticSoilProfileEntity); } } dbContext.StochasticSoilProfileEntities.RemoveRange(orphanedStochasticSoilProfileEntities); var orphanedSoilProfileEntities = new List(); foreach (SoilProfileEntity soilProfileEntity in dbContext.SoilProfileEntities .Where(e => e.SoilProfileEntityId > 0)) { if (!soilProfiles.ContainsKey(soilProfileEntity)) { orphanedSoilProfileEntities.Add(soilProfileEntity); } } dbContext.SoilProfileEntities.RemoveRange(orphanedSoilProfileEntities); var orphanedSoilLayerEntities = new List(); foreach (SoilLayerEntity soilLayerEntity in dbContext.SoilLayerEntities .Where(e => e.SoilLayerEntityId > 0)) { if (!soilLayers.ContainsKey(soilLayerEntity)) { orphanedSoilLayerEntities.Add(soilLayerEntity); } } dbContext.SoilLayerEntities.RemoveRange(orphanedSoilLayerEntities); var orphanedSurfaceLineEntities = new List(); foreach (SurfaceLineEntity surfaceLineEntity in dbContext.SurfaceLineEntities .Where(e => e.SurfaceLineEntityId > 0)) { if (!surfaceLines.ContainsKey(surfaceLineEntity)) { orphanedSurfaceLineEntities.Add(surfaceLineEntity); } } dbContext.SurfaceLineEntities.RemoveRange(orphanedSurfaceLineEntities); var orphanedSurfaceLinePointEntities = new List(); foreach (SurfaceLinePointEntity surfaceLinePointEntity in dbContext.SurfaceLinePointEntities .Where(e => e.SurfaceLinePointEntityId > 0)) { if (!surfaceLinePoints.ContainsKey(surfaceLinePointEntity)) { orphanedSurfaceLinePointEntities.Add(surfaceLinePointEntity); } } dbContext.SurfaceLinePointEntities.RemoveRange(orphanedSurfaceLinePointEntities); var orphanedCharacteristicPointEntities = new List(); foreach (CharacteristicPointEntity characteristicPointEntity in dbContext.CharacteristicPointEntities .Where(e => e.CharacteristicPointEntityId > 0)) { if (!characteristicPoints.ContainsKey(characteristicPointEntity)) { orphanedCharacteristicPointEntities.Add(characteristicPointEntity); } } dbContext.CharacteristicPointEntities.RemoveRange(orphanedCharacteristicPointEntities); var orphanedPipingFailureMechanismMetaEntities = new List(); foreach (PipingFailureMechanismMetaEntity pipingFailureMechanismMetaEntity in dbContext.PipingFailureMechanismMetaEntities .Where(e => e.PipingFailureMechanismMetaEntityId > 0)) { if (!pipingProbabilityAssessmentInputs.ContainsKey(pipingFailureMechanismMetaEntity)) { orphanedPipingFailureMechanismMetaEntities.Add(pipingFailureMechanismMetaEntity); } } dbContext.PipingFailureMechanismMetaEntities.RemoveRange(orphanedPipingFailureMechanismMetaEntities); var orphanedProbabilisticOutputEntities = new List(); foreach (ProbabilisticOutputEntity outputEntity in dbContext.ProbabilisticOutputEntities .Where(e => e.ProbabilisticOutputEntityId > 0)) { if (!probabilisticAssessmentOutputs.ContainsKey(outputEntity)) { orphanedProbabilisticOutputEntities.Add(outputEntity); } } dbContext.ProbabilisticOutputEntities.RemoveRange(orphanedProbabilisticOutputEntities); } private bool ContainsValue(Dictionary collection, U model) { if (model == null) { throw new ArgumentNullException("model"); } return collection.ContainsValue(model); } private void Register(Dictionary collection, T entity, U model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } collection[entity] = model; } private T Get(Dictionary collection, U model) { if (model == null) { throw new ArgumentNullException("model"); } return collection.Keys.Single(k => ReferenceEquals(collection[k], model)); } } }