制作实体框架模型跨越多个数据库 [英] Making an Entity Framework Model span multiple databases

查看:148
本文介绍了制作实体框架模型跨越多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有效,如

CREATE SYNONYM [dbo]。[MyTable] FOR [AnotherDatabase] .dbo。[MyTable ]

然后修改Entity Framework的edmx文件以像其他任何表一样读取此对象?

and then modify Entity Framework's edmx file to read this object like it would any other table?

我做了一个快速的样本测试,似乎可以选择和更新,但我想知道是否有任何理由,我不应该这样做

I did a quick sample test and it seems to work fine for selecting and updating, but I wanted to know if there was any reason why I shouldn't be doing this

我通过创建指向第二个数据库的edmx文件来获取表定义,在那里构建实体,然后将定义复制/粘贴到第一个数据库的edmx文件。

I am getting the table definition by creating an edmx file pointing to the 2nd database, building out the entities there, then copy/pasting the definition into the 1st database's edmx file.

更新

如果有任何人有兴趣,我写了我所做的使一个edmx文件跨多个数据库这里。它包括用于生成同义词和合并edmx文件的脚本。

If anyone is interested, I wrote up what I did to make an edmx file span mulitple databases here. It includes scripts for generating synonyms and merging edmx files.

推荐答案

如果你做了一个测试,知道关于。到目前为止,我总是回答这种类型的问题:不可能使用具有两个数据库的单一模型(根据从第二个数据库隐藏表的视图,可以使用一些更为难看的解决方法)。现在我知道两个解决方法。

If you made a test and it worked you probably showed something nobody else know about. Till now I always answered this type of question: It is not possible to use single model with two databases (with some more ugly workaround based on views hiding tables from the second database). Now I know two workarounds.

这种方法的唯一缺点是,如果您运行更新模型,则手动将所有对EDMX的SSDL部分进行的更改总是丢失来自数据库。这意味着手工开发EDMX(这是非常辛苦的工作)或使用一些工具/脚本,这将在每次更新数据库后添加更改。

The only disadvantage of this approach is that all changes made manually to SSDL part of your EDMX are always lost if you run Update model from database. This means either manual development of EDMX (which is quite hard work) or using some tool / script which will add your changes after each update from database.

这篇关于制作实体框架模型跨越多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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