不能在不同的实体框架模型相同的表名?能在、实体、框架、模型

2023-09-03 15:53:13 作者:冷瞳冷心冷少年

我的应用程序使用了两个不同的SQL 2008数据库。该数据库具有相同的名称,也就是几张桌子。 用户。我想用EF4为这两个数据库。然而,当我跑我的应用程序,它击中的ObjectContext创建第二个数据库,我收到以下错误:

My application uses two different SQL 2008 databases. The databases have a few tables with the same name, ie. Users. I would like to use EF4 for both these databases. However, when I run my application and it hits the objectcontext creation of the second database, I get the following error:

多种类型名称为用户存在   在EdmItemCollection不同   命名空间。公约基础的绘图   要求,而不考虑的唯一名称   在EdmItemCollectionto命名空间命名空间中的EdmItemCollection

Multiple types with the name 'User' exist in the EdmItemCollection in different namespaces. Convention based mapping requires unique names without regard to namespace in the EdmItemCollectionto namespace in the EdmItemCollection

这是否意味着我不能使用同一个应用程序的两个数据库与(部分)相同的表名?他们在不同的命名空间,不同的EDMX型号,不同的项目,等等。

Does this mean I can't use two databases with (partly) the same table names in the same application? They are in different namespaces, different edmx models, different projects, etc.

P.S。其中一个模型是设计器生成,并使用POCO类,另一个是从数据库推断和紧密耦合的EF

P.S. One of the models is designer-generated and uses POCO classes and the other is inferred from the database and is tightly coupled to EF.

推荐答案

该错误意味着什么,他说:你不能使用默认的约定基于映射在您的方案。使用自定义数据库映射代替。斯科特·格思里大约有详细的博客项目this.

The error means, what he says: You can't use the default convention based mapping in your scenario. Use custom database mapping instead. Scott Guthrie has a detailed blog item about this.