You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the source database is using eg. ON DELETE CASCADE in a foreign key constraint, it is completely ignored by the sync process.
Error Encountered
Working with the client database does not trigger delete cascade actions, thus resulting in FK exceptions
Problem Description
This code in GetRelationsForTableAsync:
`
var commandRelations = @"
SELECT f.name AS ForeignKey,
constraint_column_id as ForeignKeyOrder,
SCHEMA_NAME (f.schema_id) AS SchemaName,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ColumnName,
SCHEMA_NAME (reft.schema_id) AS ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.tables reft on reft.object_id = f.referenced_object_id
WHERE OBJECT_NAME(f.parent_object_id) = @tableName AND SCHEMA_NAME(f.schema_id) = @schemaName";
`
needs to be fixed as it ignores all delete_referential_action_desc and update_referential_action_desc .
Suggested Fix
I made some quick and dirty diffs:
diff --git a/Projects/Dotmim.Sync.Core/Manager/DbRelationDefinition.cs b/Projects/Dotmim.Sync.Core/Manager/DbRelationDefinition.cs
index 1b5c35da..123ef00a 100644
--- a/Projects/Dotmim.Sync.Core/Manager/DbRelationDefinition.cs
+++ b/Projects/Dotmim.Sync.Core/Manager/DbRelationDefinition.cs
@@ -37,6 +37,16 @@ namespace Dotmim.Sync.Manager
/// Gets or Sets the reference schema name.
/// </summary>
public string ReferenceSchemaName { get; set; }
+
+ /// <summary>
+ /// Gets or Sets the OnDeleteAction.
+ /// </summary>
+ public string OnDeleteAction { get; set; }
+
+ /// <summary>
+ /// Gets or Sets the OnUpdateAction.
+ /// </summary>
+ public string OnUpdateAction { get; set; }
}
/// <summary>
diff --git a/Projects/Dotmim.Sync.Core/Orchestrators/BaseOrchestrator.Schema.cs b/Projects/Dotmim.Sync.Core/Orchestrators/BaseOrchestrator.Schema.cs
index 68a78cee..9f7cd5da 100644
--- a/Projects/Dotmim.Sync.Core/Orchestrators/BaseOrchestrator.Schema.cs
+++ b/Projects/Dotmim.Sync.Core/Orchestrators/BaseOrchestrator.Schema.cs
@@ -460,7 +460,7 @@ namespace Dotmim.Sync
if (foreignColumns == null || foreignColumns.Count == 0)
continue;
- var schemaRelation = new SyncRelation(r.ForeignKey, schemaColumns, foreignColumns);
+ var schemaRelation = new SyncRelation(r.ForeignKey, schemaColumns, foreignColumns, r.OnUpdateAction, r.OnDeleteAction);
schema.Relations.Add(schemaRelation);
}
diff --git a/Projects/Dotmim.Sync.SqlServer/SqlManagementUtils.cs b/Projects/Dotmim.Sync.SqlServer/SqlManagementUtils.cs
index 40ce852c..b004faad 100644
--- a/Projects/Dotmim.Sync.SqlServer/SqlManagementUtils.cs
+++ b/Projects/Dotmim.Sync.SqlServer/SqlManagementUtils.cs
@@ -321,7 +321,9 @@ namespace Dotmim.Sync.SqlServer
COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ColumnName,
SCHEMA_NAME (reft.schema_id) AS ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
- COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName
+ COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ReferenceColumnName,
+ f.delete_referential_action_desc AS OnDeleteAction,
+ f.update_referential_action_desc AS OnUpdateAction
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.tables reft on reft.object_id = f.referenced_object_id
which are basically adding the needed sql columns to the query, adding necessary properties to the needed classes and adding a new constructor for SyncRelation .
those properties are then used in table creation on client side.
with those changes i successfully synced all my tables with cascade actions.
The text was updated successfully, but these errors were encountered:
If the source database is using eg.
ON DELETE CASCADE
in a foreign key constraint, it is completely ignored by the sync process.Error Encountered
Working with the client database does not trigger delete cascade actions, thus resulting in FK exceptions
Problem Description
This code in GetRelationsForTableAsync:
`
`
needs to be fixed as it ignores all
delete_referential_action_desc
andupdate_referential_action_desc
.Suggested Fix
I made some quick and dirty diffs:
which are basically adding the needed sql columns to the query, adding necessary properties to the needed classes and adding a new constructor for
SyncRelation
.those properties are then used in table creation on client side.
with those changes i successfully synced all my tables with cascade actions.
The text was updated successfully, but these errors were encountered: