在不同的MVC模型中有两个具有相同名称的表的问题?

时间:2022-10-26 07:51:42

I've got an ASP.NET MVC (VB) project with two models that represent two different databases. Each model needs to include a table from its database with the same name. For example, model1.dbml needs to have db1.MyTable in it, and model2.dbml needs to have db2.MyTable in it.

我有一个ASP.NET MVC(VB)项目,有两个代表两个不同数据库的模型。每个模型都需要包含其数据库中具有相同名称的表。例如,model1.dbml需要包含db1.MyTable,而model2.dbml需要包含db2.MyTable。

I can't do this because both models try to create a "Partial Public Class MyTable", and both have "Public Sub New()", so you get the "multiple definitions with identical signatures" error.

我无法做到这一点,因为两个模型都尝试创建“部分公共类MyTable”,并且都具有“Public Sub New()”,因此您将获得“具有相同签名的多个定义”错误。

There is a potential for a number of the tables between the models to have the same name. (These are separate instances of the same product used for different lines of business.) How do you get around this? Do I have to change every one of the names in one of the models to be unique? Is there a better way?

模型之间的许多表有可能具有相同的名称。 (这些是用于不同业务的相同产品的单独实例。)您如何解决这个问题?我是否必须将其中一个模型中的每个名称更改为唯一?有没有更好的办法?

2 个解决方案

#1


In the properties for the data context, there's an entity namespace property. Change that to be different for each one.

在数据上下文的属性中,有一个实体名称空间属性。改变每个人的不同。

Here is the screenshot. alt text http://img386.imageshack.us/img386/5224/98530173.jpg

这是截图。替代文字http://img386.imageshack.us/img386/5224/98530173.jpg

#2


There is a code smell to this. If your two databases are really two separate and distinct entities, then why are they in the same project; and if they are not two separate entities, then why are there two separate databases?

这有一种代码味道。如果你的两个数据库实际上是两个独立且不同的实体,那么为什么它们在同一个项目中;如果它们不是两个独立的实体,那么为什么有两个独立的数据库呢?

If you are working with one application in a portal configuration (multiple companies), then the separation can take place using a CompanyID field as a filter, and there is only ONE set of entity classes needed.

如果您正在使用门户网站配置中的一个应用程序(多个公司),则可以使用CompanyID字段作为过滤器进行分离,并且只需要一组实体类。

#1


In the properties for the data context, there's an entity namespace property. Change that to be different for each one.

在数据上下文的属性中,有一个实体名称空间属性。改变每个人的不同。

Here is the screenshot. alt text http://img386.imageshack.us/img386/5224/98530173.jpg

这是截图。替代文字http://img386.imageshack.us/img386/5224/98530173.jpg

#2


There is a code smell to this. If your two databases are really two separate and distinct entities, then why are they in the same project; and if they are not two separate entities, then why are there two separate databases?

这有一种代码味道。如果你的两个数据库实际上是两个独立且不同的实体,那么为什么它们在同一个项目中;如果它们不是两个独立的实体,那么为什么有两个独立的数据库呢?

If you are working with one application in a portal configuration (multiple companies), then the separation can take place using a CompanyID field as a filter, and there is only ONE set of entity classes needed.

如果您正在使用门户网站配置中的一个应用程序(多个公司),则可以使用CompanyID字段作为过滤器进行分离,并且只需要一组实体类。