diff --git a/Projects/Dotmim.Sync.SqlServer.ChangeTracking/SqlChangeTrackingSyncAdapter.cs b/Projects/Dotmim.Sync.SqlServer.ChangeTracking/SqlChangeTrackingSyncAdapter.cs index c381799c..25d8f262 100644 --- a/Projects/Dotmim.Sync.SqlServer.ChangeTracking/SqlChangeTrackingSyncAdapter.cs +++ b/Projects/Dotmim.Sync.SqlServer.ChangeTracking/SqlChangeTrackingSyncAdapter.cs @@ -30,7 +30,7 @@ public SqlChangeTrackingSyncAdapter(SyncTable tableDescription, ScopeInfo scopeI { DbCommandType.UpdateMetadata => (this.BuildUpdateMetadataCommand(), false), DbCommandType.SelectRow => (this.BuildSelectRowCommand(), false), - DbCommandType.DeleteMetadata => (null, false), + DbCommandType.DeleteMetadata => (this.BuildDeleteMetadataCommand(), false), DbCommandType.Reset => (this.CreateResetCommand(), false), DbCommandType.UpdateUntrackedRows => (this.BuildUpdateUntrackedRowsCommand(), false), _ => base.GetCommand(context, commandType, filter), @@ -43,6 +43,13 @@ private SqlCommand BuildUpdateMetadataCommand() return c; } + private SqlCommand BuildDeleteMetadataCommand() + { + var sqlCommand = new SqlCommand(); + sqlCommand.CommandText = $"EXEC sys.sp_flush_CT_internal_table_on_demand;"; + return sqlCommand; + } + private SqlCommand BuildSelectRowCommand() { var sqlCommand = new SqlCommand(); @@ -106,9 +113,7 @@ private SqlCommand CreateResetCommand() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"SET @sync_row_count = 0;"); - stringBuilder.AppendLine(); stringBuilder.AppendLine($"DELETE FROM {this.SqlObjectNames.TableQuotedFullName};"); - stringBuilder.AppendLine(); stringBuilder.AppendLine(string.Concat("SET @sync_row_count = @@ROWCOUNT;")); return new SqlCommand(stringBuilder.ToString());