简体   繁体   English

C# Entity Framework 6 - 如何处理具有相同表名的多个模式

[英]C# Entity Framework 6 - How to handle multiple schemas that have same table names

I'm using C# Entity Framework 6 and I have a database with multiple schemas, in those schemas I have tables with the same names.我正在使用 C# Entity Framework 6 并且我有一个包含多个模式的数据库,在这些模式中我有同名的表。 For example:例如:

  1. Rates.Hotel房价.酒店
  2. Availability.Hotel可用性.酒店

I have a single project for all of my database objects with this structure:我的所有数据库对象都有一个具有以下结构的项目:

Project Name = Storm.API.Data
In this project I have folders with the schema names: "Availability", "Rates".
In each folder I have the proper 'edmx' file.

When I run my project I'm getting this error:当我运行我的项目时,我收到此错误:

Schema specified is not valid. Errors: 

The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM 
type 'Hotel'. Previously found CLR type 'Storm.API.Data.Rates.Hotel', 
newly found CLR type 'Storm.API.Data.Availability.Hotel'.

The only solution I came up with is to separate the schemas to different project, but since I have more than 2 schemas I don't want to create so many project just for that.我想出的唯一解决方案是将模式分离到不同的项目,但由于我有 2 个以上的模式,我不想为此创建这么多项目。

Is there another solution that will enable me to have all schemas under the same project without this error ?是否有另一种解决方案可以让我在同一个项目下拥有所有架构而不会出现此错误?

You can:你可以:

  1. Give each of them a different class name in your code在你的代码中给他们每个人一个不同的类名
  2. Use 2 different DbContext classes, with a different namespace for the entities.使用 2 个不同的 DbContext 类,为实体使用不同的命名空间。 Whether you put this in another project is up to you, but not required.是否将其放在另一个项目中取决于您,但不是必需的。
  3. Not sure if this will work, but worth a shot: Make a namespace for every schema and have everything in 1 DbContext.不确定这是否可行,但值得一试:为每个模式创建一个命名空间,并将所有内容都放在 1 个 DbContext 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在实体框架C#中将表实体分配给具有相同架构的另一个表实体 - Assign Table Entity to another Table Entity with identical schemas in Entity Framework C# 不同的实体框架模型中不能有相同的表名? - Can't have the same table names in different entity framework models? 实体框架和多个模式 - Entity Framework and multiple schemas 首先在不同架构中映射具有相同表的实体 Entity Framework 6 代码 - Map entity with same table in different schemas Entity Framework 6 code first 需要帮助ServiceStack OrmLite如何使用多个联接表实体框架C#更新表 - Need help ServiceStack OrmLite how to Update table with Multiple Join table Entity Framework C# C#,实体框架,如何同时更新(删除、添加、编辑)多行? - C#, Entity Framework, How to Update(delete, add, edit) multiple rows at same time? 实体框架:如何在数据库中的同一表的模型中具有多个实体? - Entity Framework: How to have several entites in model for same table in database? 实体框架:如何具有2个引用同一张其他表的属性 - Entity Framework: How to have 2 properties referring to same other table 如何在实体框架中具有相同模式的多个表? - How to have multiple tables with the same schema in Entity Framework? 实体框架具有多个MySql模式的多个DbContext - Entity Framework Multiple DbContexts With Multiple MySql Schemas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM