简体   繁体   English

当派生表使用其自己的主键时,如何在实体框架中按类型继承设置表?

[英]How to setup table per type inhertiance in entity framework when the derived table uses its own primary key?

Suppose I have a table structure such as: 假设我有一个表结构,例如:

Order    
  ID int, primary key 
  Name, string
  OtherOrderFields...

RetailOrder
  ID int, primary key
  OrderID, foreign key
  RetailOrderFields...

In entity framework 4, is it possible to set up table per type inheritance so that RetailOrder derives from Order? 在实体框架4中,是否可以为每个类型继承设置表,以便RetailOrder从Order派生? All the examples I've seen so far have the derived class using the foreign key (OrderID in this example) as the primary key for the table, but what if that's not the case and each table maintains its own primary key? 到目前为止,我所看到的所有示例都具有使用外键(在本示例中为OrderID)作为表主键的派生类,但是如果不是这种情况并且每个表都维护自己的主键怎么办?

No, it's impossible. 不,这是不可能的。 I think, your database schema guess aggregation (1-1 relation) instead of inheritance. 我认为,您的数据库架构猜测是聚合(1-1关系)而不是继承。

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

相关问题 实体框架每个类型的表:1:0…*与派生类的FK关系-是基类还是派生类的FK? - Entity Framework table-per-type: 1:0…* FK relationship with a derived class - is FK of base class or derived class? MySql + 实体框架 = 每个派生表都必须有自己的别名 - MySql + entity framework = Every derived table must have its own alias 在使用带有实体框架的Table-per-Type时,如何仅获取基表行? - How do I get just the base table rows when using Table-per-Type with Entity Framework? 实体框架中的每种类型Fluent映射表 - Table Per Type Fluent Mapping in Entity Framework Entity Framework Core 2.0中每种类型的表 - Table per Type in Entity Framework Core 2.0 实体框架 - 每种类型的表格问题 - Entity framework - table per type issue 实体框架:软删除和每种类型的表 - Entity Framework: Soft Delete and Table per Type 如何将第一个表的主键值更新为第二个表的外键(实体框架代码第一个模型)? - How to update primary key values of first table into foreign keys in the second table (Entity framework code first model)? 如何使用 Entity Framework Core 从数据库表中确定通用实体的下一个主键? - How to determine the next primary key from a database table for a generic entity using Entity Framework Core? 实体框架数据库优先-不带主键的表 - Entity Framework database-first - table without primary key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM