MS 同步框架:表架构未复制到本地数据库 [英] MS Sync Framework: Table schema not copied to local db

查看:39
本文介绍了MS 同步框架:表架构未复制到本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 MS Sync Framework 2.0.我使用 MS SQL Server 2005 作为主数据库,使用 SQL CE 3.5 作为客户端数据库.除了主数据库中的架构没有复制到本地数据库之外,一切正常.

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.

例如:我有一个带有唯一标识符数据类型和 NEWID() 默认值的 PK 列的表.但是当schema要下载到本地数据库时,会复制PK列,但是默认值(NEWID())没有反映到本地数据库schema中.

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?

推荐答案

因此,当前的 Microsoft Sync Framework (2.0) 尚不支持此功能.我所做的是在 SqlCeClientSyncProvider 类上注册了CreatingSchema 事件,并为每个正在创建的表循环,并在 PK 中将默认值添加到 NEWID().

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().

声明:

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

注册事件:

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

事件:

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

这篇关于MS 同步框架:表架构未复制到本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆