Skip to content

Commit

Permalink
Address are imported multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
DWDBE committed Apr 15, 2024
1 parent d008773 commit 5252177
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.17</Version>
<Version>10.0.18</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>User Provider</Title>
<Description>User Provider</Description>
Expand Down
12 changes: 6 additions & 6 deletions src/UserDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,13 @@ private void DeleteExcessFromMainTable(Mapping mapping, string extraConditions,
sqlClean.Append($" WHERE NOT EXISTS (SELECT * FROM [{mapping.DestinationTable.SqlSchema}].[{tempTableName}TempTableForBulkImport{mapping.GetId()}] where ");

var columnMappings = mapping.GetColumnMappings();
bool isPrimaryKeyColumnExists = columnMappings.Any(cm => cm.Active && ((SqlColumn)cm.DestinationColumn).IsPrimaryKey);
bool isPrimaryKeyColumnExists = columnMappings.IsKeyColumnExists();
foreach (ColumnMapping columnMapping in columnMappings)
{
if (columnMapping.Active)
{
SqlColumn column = (SqlColumn)columnMapping.DestinationColumn;
if (column.IsPrimaryKey || !isPrimaryKeyColumnExists)
if (column.IsKeyColumn(columnMappings) || !isPrimaryKeyColumnExists)
{
sqlClean.Append($"[{mapping.DestinationTable.SqlSchema}].[{destinationTableName}].[{column.Name}]=[{column.Name}] AND ");
}
Expand Down Expand Up @@ -1092,8 +1092,8 @@ private void MoveDataToMainTable(Mapping mapping, SqlTransaction sqlTransaction)
{
string sqlConditions = "";
string firstKey = "";
var columnMappings = mapping.GetColumnMappings();
bool isPrimaryKeyColumnExists = columnMappings.Any(cm => cm.Active && ((SqlColumn)cm.DestinationColumn).IsPrimaryKey);
var columnMappings = mapping.GetColumnMappings();
bool isPrimaryKeyColumnExists = columnMappings.IsKeyColumnExists();
if (UseAutoSearching && !isPrimaryKeyColumnExists && mapping.DestinationTable.Name != "AccessUserGroup" && mapping.DestinationTable.Name != "AccessUserAddress")
{
sqlConditions = sqlConditions + "[" + mapping.DestinationTable.SqlSchema + "].[" +
Expand All @@ -1109,7 +1109,7 @@ private void MoveDataToMainTable(Mapping mapping, SqlTransaction sqlTransaction)
if (columnMapping.Active)
{
SqlColumn column = (SqlColumn)columnMapping.DestinationColumn;
if (column.IsPrimaryKey || (!isPrimaryKeyColumnExists && !columnMapping.ScriptValueForInsert))
if (column.IsKeyColumn(columnMappings) || (!isPrimaryKeyColumnExists && !columnMapping.ScriptValueForInsert))
{
sqlConditions = sqlConditions + "[" + mapping.DestinationTable.SqlSchema + "].[" +
destinationTableName + "].[" + columnMapping.DestinationColumn.Name + "]=[" +
Expand All @@ -1132,7 +1132,7 @@ private void MoveDataToMainTable(Mapping mapping, SqlTransaction sqlTransaction)
if (columnMapping.Active)
{
insertColumns.Add("[" + columnMapping.DestinationColumn.Name + "]");
if (!((SqlColumn)columnMapping.DestinationColumn).IsIdentity && !((SqlColumn)columnMapping.DestinationColumn).IsPrimaryKey && !columnMapping.ScriptValueForInsert)
if (!((SqlColumn)columnMapping.DestinationColumn).IsIdentity && !((SqlColumn)columnMapping.DestinationColumn).IsKeyColumn(columnMappings) && !columnMapping.ScriptValueForInsert)
updateColumnList.Add("[" + columnMapping.DestinationColumn.Name + "]=[" + mapping.DestinationTable.SqlSchema + "].[" + tempTableName + "TempTableForBulkImport" + mapping.GetId() + "].[" + columnMapping.DestinationColumn.Name + "]");
insertSelectList.Add("[" + tempTableName + "TempTableForBulkImport" + mapping.GetId() + "].[" + columnMapping.DestinationColumn.Name + "]");
}
Expand Down

0 comments on commit 5252177

Please sign in to comment.