实体框架中的复杂继承
这是我在这里发表的第一篇文章。预先感谢所有与我合作的人。
我正在开发一个新的 MER,这是其中的一部分: https://i.sstatic .net/jt5Mz.png。
在链接的 MER 中,我在实体上使用每个层次结构表:Person、公司和个人。驱动程序实体基于每种类型的表。
我的大问题是司机可以是个人或公司。
个人或公司都继承自个人,后者拥有两个实体的公共字段。
有一种方法可以使用每种类型的表格使驾驶员实体灵活地成为个人或公司 > 在 Driver 实体上?
谢谢大家!!!
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: https://i.sstatic.net/jt5Mz.png.
In the linked MER, i'm using Table per Hierarchy on entities: Person, Company and Individual. 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.
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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要更改它,以便 Driver HAS A Person 而不是 Driver IS A Person。即,您有一个单独的 Driver 类,它有一个名为“人员”的字段,“人员”可以是个人也可以是公司。
或者您应该将 DriverNumber 字段移至 Person 类,以便个人(个人或公司)碰巧有司机号码时可以成为“司机”。
I think you need to change it so that Driver HAS A Person instead of Driver IS A Person. i.e. 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.
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.
为什么不更改设计以表明“Driver”是“关联的”(0..1),而不是从 Person 继承。基本上使“司机”成为一个可选的人实体,然后个人或公司都将继承它。
Why not change the design to say that a 'Driver' is 'associated' (0..1) rather than inherited from a Person. Basically making 'driver' an optional entity of person then both individual or company will inherit this.