Syncframework 2.1处理InsertConflicts

时间:2016-12-05 14:19:05

标签: c# sql-server microsoft-sync-framework

我有一个使用Sync framework 2.1的应用程序。

数据模型: enter image description here

当2个客户端插入新行(例如新产品)并生成包含新产品的新订单时,我会收到LocalInsertRemoteInsert消息。当我处理此消息时,我收集冲突行的字段并重新插入此行以获取新ID。

例如:

客户端1插入ID为2的产品和包含ProductID 2的订单ID 1的订单

客户端2插入ID为2的产品和包含ProductID 2的订单ID 1的订单

同步后,表格中都填充了产品和订单,但...... client2的顺序具有客户端1所生产的产品的外键。因为客户端2的产品具有新ID(在这种情况下ID将为3)。

我尝试使用GUID(uniqueidentifier)作为ID进行修复,但Syncframework不接受uniqueidentifier,我收到错误:“操作数类型冲突:uniqueidentifier与int不兼容”。当我尝试定义范围时......

我用来创建范围的代码:

 private void Define_Server(string tableName)
        {
            // define a new scope named ProductsScope
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(tableName+"Scope");

            // get the description of the Products table from SyncDB dtabase
            DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, _serverConnection);

            // add the table description to the sync scope definition
            scopeDesc.Tables.Add(tableDesc);

            // create a server scope provisioning object based on the ProductScope
            SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(_serverConnection, scopeDesc);

            // skipping the creation of table since table already exists on server
            serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

            try
            {
                if (!serverProvision.ScopeExists(tableName + "Scope"))
                {
                    // start the provisioning process
                    serverProvision.Apply();
                    log.Info(String.Format("Succesfully provise the {0}Scope in the server", tableName));
                }

            }
            catch (Exception ex)
            {

                log.Error(ex);
            }

        }

1 个答案:

答案 0 :(得分:1)

Sync Framework与GUID一起使用。但是,Sync Framework不执行模式同步。当您修改架构/数据类型时,它也不会更新其元数据/对象。

如果你更改了数据类型,只需取消配置数据库并重新配置,你应该好好去。