Skip to content

Commit

Permalink
Merge pull request #33 from dynamicweb/mss/21058-MappingExtensions-Au…
Browse files Browse the repository at this point in the history
…toID

Removed local ReplaceKeyColumnsWithAutoIdIfExists and replaced call t…
  • Loading branch information
frederik5480 authored Oct 3, 2024
2 parents 903a6e9 + e3ecb37 commit 8d3db16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 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.7.0</Version>
<Version>10.8.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.7.0" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.8.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
24 changes: 3 additions & 21 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 = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
_columnMappings = new ColumnMappingCollection(MappingExtensions.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 = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
_columnMappings = new ColumnMappingCollection(MappingExtensions.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 = new ColumnMappingCollection(ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
_columnMappings = new ColumnMappingCollection(MappingExtensions.ReplaceKeyColumnsWithAutoIdIfExists(Mapping));
SqlCommand = mockSqlCommand;
this.removeMissingAfterImport = removeMissingAfterImport;
this.logger = logger;
Expand Down Expand Up @@ -179,24 +179,6 @@ 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 8d3db16

Please sign in to comment.