实体框架映射存在于两个数据库中的同一个表 [英] Entity Framework map same table that exists in two databases

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

问题描述

使用实体框架正确映射以下内容有哪些选项:

What options are available to correctly map the following using Entity Framework:

数据库1表:
Foo,Foo_Assets,Assets

Database 1 tables: Foo, Foo_Assets, Assets

数据库2表:
Bar,Bar_Assets,Assets

Database 2 tables: Bar, Bar_Assets, Assets

我已经将映射栏,Bar_Assets,Assets作为SQL视图,或者从数据库2加载这些表时使用不同的数据库上下文。

I have considered mapping Bar, Bar_Assets, Assets as SQL views, or using a different db context when loading these tables from Database 2. 

挑战是尽管Foo,Bar及其_Assets表可以单独对待,但两个数据库都具有资产表。这些表如何正确映射到资产实体?

The challenge is that although Foo, Bar and their _Assets tables can be treated independently, both databases have an Assets table. How can these tables be correctly mapped to the Asset entity?

推荐答案

由于您有2个数据库,您将拥有2个edmx文件。只有在edmx中使用不同的名称才能使用资产表。这样就可以确保没有冲突。

Since you have 2 databases, you will have 2 edmx files. Just having a different name in the edmx for Assets table will work. This way you can ensure that there are no clashes.

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

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