Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address are imported multiple times #26

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading