MS 同步框架:表架构未复制到本地数据库

编程入门 行业动态 更新时间:2024-10-15 12:36:18
本文介绍了MS 同步框架:表架构未复制到本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在我的项目中使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 14:04:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410454.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   框架   数据库   MS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!