开发者

MS Sync Framework: Table schema not copied to local db

Im working with a MS Sync Framework 2.0 o开发者_如何学Pythonn 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?


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()";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜