From 2be0d04986fad10ef43e72183589f50bfa8ab247 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Wed, 28 Aug 2024 09:45:07 +0200 Subject: [PATCH 1/2] added function to check and replace if the auto-id column exists in the column mappings. Bump version to 10.7.0 --- ...Integration.Providers.OrderProvider.csproj | 6 +++--- src/OrderProvider.cs | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj index 15e138e..c0069db 100644 --- a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj @@ -1,6 +1,6 @@  - 10.6.1 + 10.7.0 1.0.0.0 Order Provider Order Provider @@ -23,8 +23,8 @@ snupkg - - + + diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index 4542331..e604a50 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -336,6 +336,24 @@ internal static List GetMappingsByName(MappingCollection collection, st } } + internal static IEnumerable ReplaceKeyColumnsWithAutoIdIfExists(Mapping mapping) + { + //will move this to MappingExtensions - US https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/20900 + if (mapping == null) return []; + + var autoIdDestinationColumnName = MappingExtensions.GetAutoIdColumnName(mapping.DestinationTable?.Name ?? ""); + if (string.IsNullOrEmpty(autoIdDestinationColumnName)) return mapping.GetColumnMappings(); + + var columnMappings = mapping.GetColumnMappings().ToList(); + var autoIdColumnMapping = columnMappings.Where(obj => obj.DestinationColumn.Name.Equals(autoIdDestinationColumnName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); + if (autoIdColumnMapping != null) + { + columnMappings.ForEach(obj => obj.IsKey = false); + autoIdColumnMapping.IsKey = true; + } + return columnMappings; + } + public override bool RunJob(Job job) { OrderTablesInJob(job, false); @@ -357,8 +375,8 @@ public override bool RunJob(Job job) Logger.Log("Starting import to temporary table for " + mapping.DestinationTable.Name + "."); using (var reader = job.Source.GetReader(mapping)) { + var columnMappings = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(mapping)); var writer = new OrderDestinationWriter(mapping, Connection, Logger, SkipFailingRows, DiscardDuplicates); - var columnMappings = mapping.GetColumnMappings(); while (!reader.IsDone()) { sourceRow = reader.GetNext(); From fe62d284cdb144e38e30bc4221fde52df4ff78df Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Wed, 28 Aug 2024 09:46:03 +0200 Subject: [PATCH 2/2] made function private --- src/OrderProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index e604a50..1c5e62c 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -336,7 +336,7 @@ internal static List GetMappingsByName(MappingCollection collection, st } } - internal static IEnumerable ReplaceKeyColumnsWithAutoIdIfExists(Mapping mapping) + private static IEnumerable ReplaceKeyColumnsWithAutoIdIfExists(Mapping mapping) { //will move this to MappingExtensions - US https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/20900 if (mapping == null) return [];