简体   繁体   English

实体框架中的复杂继承

[英]Complex Inheritance in Entity Framework

That's my first post here. 这是我在这里的第一篇文章。 Thanks in advance everyone that collaborates with me. 预先感谢与我合作的每个人。

I'm working on a new MER, this is a piece of the it: http://i.stack.imgur.com/jt5Mz.png . 我正在开发新的MER,这只是其中的一部分: http : //i.stack.imgur.com/jt5Mz.png

替代文字

In the linked MER, i'm using Table per Hierarchy on entities: Person, Company and Individual. 在链接的MER中,我对实体(人,公司和个人)使用“ 每个层次的表” Driver entity is on based on Table per Type . 驱动程序实体基于每个类型的表

My big problem is that a Driver can be Individual or Company . 我的大问题是, 驾驶员可以是个人公司

Both Individual or Company inherites from Person that holds common fields from both entities. 个人公司都继承自拥有两个实体公共字段的 Person

There is a way to make the Driver entity flexible to be an Individual or a Company , using the Table per Type on Driver entity? 有没有一种方法可以使用驱动程序实体上每种类型使驱动程序实体灵活地成为个人公司

Thanks you all!!! 谢谢大家!

I think you need to change it so that Driver HAS A Person instead of Driver IS A Person. 我认为您需要更改它,以便驾驶员拥有一个人而不是驾驶员成为一个人。 ie you have a separate Driver class and it has a field on it called Person and that 'Person' is either an individual or a company. 也就是说,您有一个单独的Driver类,并且在其上具有一个名为Person的字段,并且“ Person”是个人还是公司。

OR you should move the DriverNumber field to the Person class so that a Person (Individual or Company) can be a 'Driver' if they happen to have a driver number. 或者,您应该将DriverNumber字段移至Person类,这样,如果一个人(个人或公司)碰巧有一个驾驶员编号,则可以成为“驾驶员”。

Why not change the design to say that a 'Driver' is 'associated' (0..1) rather than inherited from a Person. 为什么不将设计更改为说“驱动程序”是“关联的”(0..1),而不是继承自Person。 Basically making 'driver' an optional entity of person then both individual or company will inherit this. 基本上使“驾驶员”成为个人的可选实体,然后个人或公司都将继承该实体。

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

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