我有一個應用程序使用Sync框架2.1。Syncframework 2.1 handeling InsertConflicts
當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);
}
}
我已經使用GUIDs Syncframework沒有問題,不記得任何限制。 –