Skip to content

Commit

Permalink
Merge pull request #31 from dynamicweb/mss/20221-AUtoID
Browse files Browse the repository at this point in the history
added function to check and replace if the auto-id column exists in t…
  • Loading branch information
frederik5480 authored Aug 29, 2024
2 parents daa44ec + 3e95182 commit 3f75526
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Dynamicweb.DataIntegration.Providers.SqlProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.0</Version>
<Version>10.7.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>SQL Provider</Title>
<Description>SQL Provider</Description>
Expand All @@ -23,7 +23,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.6.3" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.7.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
24 changes: 21 additions & 3 deletions src/SQLDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo
public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool removeMissingAfterImport, ILogger logger, string tempTablePrefix, bool discardDuplicates)
{
Mapping = mapping;
_columnMappings = Mapping.GetColumnMappings();
_columnMappings = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
SqlCommand = connection.CreateCommand();
SqlCommand.CommandTimeout = 1200;
this.removeMissingAfterImport = removeMissingAfterImport;
Expand All @@ -118,7 +118,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo
public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool removeMissingAfterImport, ILogger logger, bool discardDuplicates)
{
Mapping = mapping;
_columnMappings = Mapping.GetColumnMappings();
_columnMappings = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
SqlCommand = connection.CreateCommand();
SqlCommand.CommandTimeout = 1200;
this.removeMissingAfterImport = removeMissingAfterImport;
Expand All @@ -145,7 +145,7 @@ public SqlDestinationWriter(Mapping mapping, SqlConnection connection, bool remo
public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool removeMissingAfterImport, ILogger logger, string tempTablePrefix, bool discardDuplicates)
{
Mapping = mapping;
_columnMappings = Mapping.GetColumnMappings();
_columnMappings = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
SqlCommand = mockSqlCommand;
this.removeMissingAfterImport = removeMissingAfterImport;
this.logger = logger;
Expand Down Expand Up @@ -179,6 +179,24 @@ public SqlDestinationWriter(Mapping mapping, SqlCommand mockSqlCommand, bool rem
}
}

private static IEnumerable<ColumnMapping> 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;
}

/// <summary>
/// Writes the specified row.
/// </summary>
Expand Down

0 comments on commit 3f75526

Please sign in to comment.