每个层次结构表和继承实现问题
我正在将旧的 ASP 应用程序迁移到现代 .NET 版本,为了减少开发时间,我们正在考虑 .NET 4.0 实体框架。然而,我们在开发过程中似乎遇到了这个问题。
给出的是我们数据库的一小部分: 一个表 OBJECT,其中包含汽车及其各自属性的列表。我们还有一个表 OBJECT_OPTIONS,其中包含 OBJECT 中给定汽车的选项、配件和标准设备的列表。这三种类型都具有相同的字段,因此存储在同一个表中。 ncopt_type 列用于区分不同的列表。可能的值为:“opt”、“acc”和“sta”。表 OBJECT_OPTIONS 通过 ncopt_obj_id 链接到 OBJECT,它表示表 OBJECT 中唯一的汽车 (obj_id)。
我们的目标是为 OBJECT 实体提供 3 个链接到不同 OBJECT_OPTIONS 列表的属性: - 财产选择 - 财产配件 - 属性标准设备
我们已经通过继承模型尝试了有关每个层次结构表的不同教程和演练,但尚未成功创建可构建的模型。
从技术上讲,我们所做的是:
- 创建实体 OBJECT
- 创建实体 OBJECT_OPTIONS,使其抽象
- 添加实体 OPTION、ACCESSORY 和 STANDARD_EQUIP 全部使用基本类型 OBJECT_OPTIONS
- 向 ncopt_type = '...' 上的所有三个表添加条件
- 向 OBJECT 添加 3 个导航属性,全部链接到继承的实体之一:选项、配件和标准设备
在此设置过程中会出现一堆错误,但我们最终得到的是这个:
错误 3032:从第 250、286 行开始的映射片段出现问题:EntityTypes NCO.Model.OPTION、NCO.Model.ACCESSOIRE、NCO.Model.STANDAARD_EQUIP 正在映射到表 OBJECT_OPTIES 中的相同行。映射条件可用于区分这些类型映射到的行。
但所有三个物体都存在一个条件。
我还没有找到解决这个问题的方法,并且已经在上面花费了太多时间。我们目前正在使用一种解决方法,但希望解决这个问题,因为这种情况在项目结束时会多次出现。
感谢任何帮助,如果您需要更多信息,请给我留言或发送电子邮件。
I am migrating an old ASP application to a modern .NET version, to cut down on development times we are looking at the .NET 4.0 Entity Framework. However, we seem to have hit a brick wall in our development with this issue.
Given is a small part of our database:
A table OBJECT which contains a list of cars and their respective properties. We also have a table OBJECT_OPTIONS which contains, for a given car in OBJECT, a list of OPTIONS, ACCESSORIES and STANDARD EQUIPMENT. These three types all have the same fields and are therefor stored in the same table. The column ncopt_type is used to discriminate between the different lists. Possible values are: 'opt', 'acc' and 'sta'. The table OBJECT_OPTIONS links to OBJECT via ncopt_obj_id which represents a unique car (obj_id) in table OBJECT.
Our goal is to provide the OBJECT entity with 3 properties that link to the different OBJECT_OPTIONS lists:
- property OPTIONS
- property ACCESSORIES
- property STANDARDEQUIPMENT
We've tried different tutorials and walkthroughs concerning the table-per-hierarchy via inheritance model but haven't succeeded in creating a buildable model.
Technically what we did was:
- Create entity OBJECT
- Create entity OBJECT_OPTIONS, make it abstract
- Add entities OPTION, ACCESSORY and STANDARD_EQUIP all using basetype OBJECT_OPTIONS
- Add conditions to all three tables on ncopt_type = '...'
- Add 3 navigational properties to OBJECT, all linking to one of the inherited entities: OPTIONS, ACCESSORIES and STANDAARD_EQUIPMENT
A bunch of errors shows up during this setup, but we end up with this one:
Error 3032: Problem in mapping fragments starting at lines 250, 286:EntityTypes NCO.Model.OPTION, NCO.Model.ACCESSOIRE, NCO.Model.STANDAARD_EQUIP are being mapped to the same rows in table OBJECT_OPTIES. Mapping conditions can be used to distinguish the rows that these types are mapped to.
There is a condition present on all three objects though.
I have found no solution to this problem and have spent way too much time on it already. We are currently using a workaround method but would love to get this fixed as this situation will present itself a few more times by the end of the project.
Any help appreciated, if you need more information, please drop me a comment or an email.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信您可以在 EF 设计器中 100% 地完成此操作,但您可以这样做:
然后使用车辆的部分类添加所需的属性:
I'm not convinced you can do this 100% from within the EF designer, but you can do it like this:
Then add in the properties you want using a partial class for Vehicle: