EF4 跨数据库关系

发布于 2024-08-30 03:40:29 字数 232 浏览 3 评论 0原文

我想知道 EF4 是否支持跨数据库关系?例如:

db1

Author
  Id
  Name

db2

Posts
  Id
  Content
  db1.Author.Id

理想情况下我需要做什么才能在我的 ef4 模型中获得此关系?

你们有什么想法吗?

谢谢

I was wondering if EF4 support cross-databse relationships? For instance:

db1

Author
  Id
  Name

db2

Posts
  Id
  Content
  db1.Author.Id

What ideally I need to do to get this relation in my ef4 model?

Do you guys have any idea?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葵雨 2024-09-06 03:40:29

我发现 Microsoft Connect 中的此条目回答了有关支持的问题目前由 EF 给出(实际上还不支持)。

还发现社交 MSDN 中的一个线程 关于这个问题。

Stack Overflow 上的其他链接:

总之,唯一给出的替代方案是:

  1. 在 EF 中使用视图

  2. 使用 NHibernate 代替

I've found this entry in Microsoft Connect that answers the question about the support given at this moment by EF (actually it is not supported yet).

Also found a thread in Social MSDN about this concern.

Other links on Stack Overflow:

In summary, the only given alternatives are:

  1. Using views in EF

  2. Use NHibernate instead

感悟人生的甜 2024-09-06 03:40:29

如果您的数据库支持同义词,您可以欺骗 EF 跨越多个数据库。我在这里写了如何做到这一点。

基本上,您最终会得到每个数据库一个 edmx 文件,以及一个将它们合并到单个 edmx 文件中的脚本。同义词用于通过实际表名称从另一个数据库引用一个数据库,因此当您尝试从数据库 1 访问数据库 2.table 时,EF 不会出现异常。您仍然必须在 EF 模型中手动设置两个数据库之间的链接,但设置后,即使您重新运行合并脚本,它们也会保留。

设置同义词和合并 edmx 文件的脚本发布在链接中

If your database supports Synonyms, you can trick EF to span multiple databases. I wrote up how to do it here.

Basically you end up with an edmx file per database, and a script which merges them into a single edmx file. Synonyms are used to reference one database from another by using the actual table name, so EF doesn't throw a fit when you try to access database2.table from database1. You still have to setup links between the two databases manually in the EF model, but once setup they'll stay even if you re-run the merge script.

Scripts to setup Synonyms and to merge the edmx files are posted in the link

枉心 2024-09-06 03:40:29

我最近开始了一个项目,该项目使用带有两个数据库(一个 Oracle 和一个 SQL Server)的实体框架。我在实体框架中找不到有关跨数据库或多数据库支持的任何信息。

MS 实体框架团队的大多数帖子都是几年前发布的,表明在单个模型中包含两个数据库并不是很快就会包含的功能。我很想知道它是否包含在 2010 年我自己的具体答案中,尽管我怀疑答案是否定的。

目前的项目通过为每个数据库提供单独的实体模型来解决此限制。这已经解决了我们迄今为止在项目中遇到的大多数场景的问题。

如果我们需要同时从两个数据库查询数据,我们只需在一个或另一个数据库中创建一个视图即可。由于我们使用 Oracle 和 SQL Server,因此该视图将使用链接服务器 (SQL) 或 DBLink (Oracle)。

实体框架中视图的缺点是我们必须花费比我预期更多的时间来使主键正常工作。

希望这有帮助。

I recently began a project that uses entity framework with two databases, one Oracle and one SQL Server. I could not find any information regarding cross-database or multiple database support in the entity framework.

Most posts from the MS Entity framework team are a couple of years old and indicate that including two databases in a single model is not a feature that will be included soon. I would be interested in having a concrete answer on whether it was included in 2010 myself although I suspect the answer is no.

Currently out project gets around this limitation by having a separate entity model for each database. This has solved the problem for the majority of the scenarios we've encountered thus far in the project.

In cases where we've needed to query the data from the two databases at the same time, we simply created a view in one or the other databases. Since we're using Oracle and SQL Server, this view would utilize either a Linked Server (SQL) or a DBLink (Oracle).

The disadvantage of views in the entity framework is we've had to spent more time than I expected getting the primary keys working.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文