简体   繁体   English

使用实体框架将实体分成2个表

[英]Splitting an entity into 2 tables with Entity Framework

I have 2 tables in my database (Oracle) which I would like to merge into one entity. 我的数据库(Oracle)中有2个表,我想将它们合并成一个实体。 I'm using Entity Framework 4.1 code first approach (with existing database) so everything works fine. 我使用的是Entity Framework 4.1代码优先方法(与现有数据库一起使用),因此一切正常。

The tables structure: 表结构:

Table Document_Metadata: 表Document_Metadata:

Item       NUMBER(2)   PK
Version    NUMBER(2)   PK 
DocDate    DATE        PK
RepType    NUMBER(2)   PK
ValueType  NUMBER(2)   PK
DocId      NUMBER(5)   NOT NULL FK -> Document table
User       VARCHAR2(5) NOT NULL
RowVersion DATE        NOT NULL

Table Document: 表格文件:

ID         NUMBER(5)   PK
Doc        LONGRAW     
User       VARCHAR2(5) NOT NULL
RowVersion DATE        NOT NULL

Is there a way to accomplish that, and if so how would I do that? 有没有办法做到这一点,如果可以的话,我该怎么做?

Thanks in advanced. 提前致谢。

I don't think you can do that. 我认为您无法做到。 If this is "one to one" relation, maybe you could go with table per type inheritance, and inherit Document_Metadata class from Document class. 如果这是“一对一”的关系,则也许可以将表与每个类型继承一起使用,并从Document类继承Document_Metadata类。 So you would have one entity object for both tables. 因此,两个表都将有一个实体对象。 But for that to work DocID would have to be PK in Document_Metadata and I think that primary key column names for both tables would have to be same (rename ID to DocID in Document table). 但是要使其正常工作,DocID必须在Document_Metadata中为PK,并且我认为两个表的主键列名称必须相同(将ID重命名为Document表中的DocID)。 But that requires changes in your database model. 但这需要更改数据库模型。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM