添加 FilterClause 后,删除不再起作用。
JuneT 表示对跟踪表的过滤器是 Users_tracking
但是,我在 Users_tracking 中没有看到 IsPublished 列;我只看到用户 ID。
感谢您的帮助!
private static void ProvisionLocal(
SqlConnection sqlLocalConn, DbSyncScopeDescription scopeDesc)
{
var Users = SqlSyncDescriptionBuilder
.GetDescriptionForTable("Users", sqlLocalConn);
scopeDesc.Tables.Add(Users);
var sqlLocalProv = new SqlSyncScopeProvisioning(sqlLocalConn, scopeDesc);
sqlLocalProv.CommandTimeout = 3600;
sqlLocalProv.Tables["Users"].AddFilterColumn("IsPublished");
sqlLocalProv.Tables["Users"].FilterClause =
string.Format("[side].[IsPublished] = {0}", 1);
if (!sqlLocalProv.ScopeExists("TestScope"))
{
sqlLocalProv.Apply();
}
}
private static void ProvisionRemote(
SqlConnection sqlRemoteConn, DbSyncScopeDescription scopeDesc)
{
var sqlRemoteProv = new SqlSyncScopeProvisioning(sqlRemoteConn, scopeDesc);
sqlRemoteProv.CommandTimeout = 3600;
if (!sqlRemoteProv.ScopeExists("TestScope"))
{
// Apply the scope provisioning.
sqlRemoteProv.Apply();
}
}
public void Synchronize()
{
var sqlSourceConn = new SqlConnection("...");
var sqlDestinationConn = new SqlConnection("...");
var scopeDesc = new DbSyncScopeDescription("TestScope");
ProvisionLocal(type, sqlSourceConn, scopeDesc);
ProvisionRemote(type, sqlDestinationConn, scopeDesc);
// Prepare for synchronization
var localProvider = new SqlSyncProvider("TestScope", sqlSourceConn);
var remoteProvider = new SqlSyncProvider("TestScope", sqlDestinationConn);
remoteProvider.ApplyChangeFailed += RemoteProvider_ApplyChangeFailed;
var orch = new SyncOrchestrator();
orch.RemoteProvider = remoteProvider;
orch.LocalProvider = localProvider;
orch.Direction = SyncDirectionOrder.Upload;
SyncOperationStatistics stats = orch.Synchronize();
sqlDestinationConn.Close();
sqlSourceConn.Close();
}