实体框架多对多的疯狂

时间:2022-10-05 15:04:13

实体框架多对多的疯狂

Ok, don't shoot me for the following db structure. I inherited this, I did not create it. What I'm trying to do though is to simplify my life. I'm currently using EF 4.1 Code First and I know how to do many-to-many mappings through tables with the fluent api, but I'm completely lost as to how to handle this structure. Bascially I'd like to be able to map from the IDB_interface table to the IDB_AddressIPv4 table by using a single navigation property? However, I'm guessing this isn't possible? Any constructive thoughts or suggestions would be greatly appreciated. Starting over isn't an option or changing the db structure.

好吧,不要拍我以下的数据库结构。我继承了这个,我没有创造它。我想做的是简化我的生活。我目前正在使用EF 4.1 Code First,我知道如何使用流畅的api通过表进行多对多映射,但我完全不知道如何处理这种结构。基本上我希望能够通过使用单个导航属性从IDB_interface表映射到IDB_AddressIPv4表?但是,我猜这不可能吗?任何建设性的想法或建议将不胜感激。重新开始不是一个选项或更改数据库结构。

Thanks in advance.

提前致谢。

1 个解决方案

#1


2  

You must live with the structure you have. EF code first has no tools to help you. It can only simplify many-to-many relation with single junction table without additional data - that is not your case.

你必须忍受你拥有的结构。 EF代码首先没有工具可以帮助您。它只能在没有附加数据的情况下简化与单接口表的多对多关系 - 这不是您的情况。

This is a case where it would be really handy to add additional layer on top of EF which would simplify your model to desired entities and your persistence logic will transform it to this horror.

在这种情况下,在EF上添加额外的图层会非常方便,这会将模型简化为所需的实体,而持久性逻辑会将其转换为恐怖。

#1


2  

You must live with the structure you have. EF code first has no tools to help you. It can only simplify many-to-many relation with single junction table without additional data - that is not your case.

你必须忍受你拥有的结构。 EF代码首先没有工具可以帮助您。它只能在没有附加数据的情况下简化与单接口表的多对多关系 - 这不是您的情况。

This is a case where it would be really handy to add additional layer on top of EF which would simplify your model to desired entities and your persistence logic will transform it to this horror.

在这种情况下,在EF上添加额外的图层会非常方便,这会将模型简化为所需的实体,而持久性逻辑会将其转换为恐怖。