2016-12-05 83 views
1

我有一个应用程序使用Sync框架2.1。Syncframework 2.1 handeling InsertConflicts

的数据模型: enter image description here

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

例如:

客户端1个插入产品ID为2,并用订单ID 1包含的ProductID 2

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

的顺序的顺序

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

我试图用GUID(uniqueidentifier)作为ID修复它,但Syncframework不接受uniqueidentifier's,我收到错误:“操作数类型冲突: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); 
      } 

     } 
+0

我已经使用GUIDs Syncframework没有问题,不记得任何限制。 –

回答

1

同步框架与工作的GUID。但Sync Framework不会执行模式同步。当你修改模式/数据类型时,它也不会更新它的元数据/对象。

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