MS Sync Framework: Table schema not copied to loca

2019-08-31 02:09发布

Im working with a MS Sync Framework 2.0 on my project. I am using MS SQL Server 2005 as the main DB and SQL CE 3.5 for the client DB. Everything's working fine except that the schema from the main db is not copied to the local db.

for example: I have a table with a PK column with uniqueidentifier datatype and a NEWID() default value. but when the schema is to be downloaded to the local database, the PK column is copied but the default value (NEWID()) is not reflected to the local DB schema.

any solutions to this? is there a requirement?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-31 02:57

So this is not yet supported in the current Microsoft Sync Framework (2.0). What I did was that I registered for the CreatingSchema event on the SqlCeClientSyncProvider class and looped for each table being created and added a default value at the PKs to NEWID().

declaration:

SqlCeClientSyncProvider clientProvider = new SqlCeClientSyncProvider(<connectionstring here>);

registering event:

clientProvider.CreatingSchema += new EventHandler<Microsoft.Synchronization.Data.CreatingSchemaEventArgs>(clientProvider_CreatingSchema);

the event:

if (e.Table.SyncDirection == SyncDirection.Bidirectional)
{
    if (e.Schema.Tables[e.Table.TableName].Columns[0].DataType == typeof(Guid))
       e.Schema.Tables[e.Table.TableName].Columns[0].DefaultValue = "NEWID()";
}
查看更多
登录 后发表回答