实体框架模型从两个数据库 [英] Entity Framework Model from two databases

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

问题描述

可以从两个数据库中创建一个实体模型,表中的所有关系都反映在模型中?你如何做?

Is it possible to have an entity model created out of two databases, with all the relationships between tables reflected in the model? How do you do that?

我是指ADO.NET Entity Framework版本4。

I am referring to ADO.NET Entity Framework version 4.

推荐答案

也许这取决于几个因素。

Maybe. It depends on several factors.

如果使用现代版本的SQL Server,有一个名为Synonyms的功能,它允许您将表从一个数据库映射到另一个数据库。

If using a modern version of SQL Server, there is a feature called Synonyms, which allows you to "map" a table from one database into another.

不幸的是,EF Data设计师不能识别或理解同义词。有一种方法可以将两个.EDMX文件手动合并为一个,但这是一个巨大的痛苦。

Unfortunately, the EF Data designer doesn't recognize or understand Synonyms. There is a way to manually merge two .EDMX files into one, but this is a huge pain.

当使用同义词时,我更喜欢使用Code First方法。我使用实体框架电动工具扩展来将表反向工程到代码第一模型,这对于同义词很好。

When using Synonyms, I prefer to use the Code First approach. I use the Entity Framework Power Tools extension to reverse engineer the tables to a code first model, and this works fine with synonyms.

如果要使用.EDMX,那么您可以尝试以下方法:

If you want to use .EDMX, then you can try the approach here:

http://rachel53461.wordpress.com/2011/05/ 22 / tricking-ef-to-span-multiple-databases /

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

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