In EF4.1+, do you have to expose a foreign key property on a dependent entity to enforce an identifying relationship?

☆樱花仙子☆ 提交于 2019-12-24 09:24:01

问题


If I want to create an identifying relationship using EF 4.1+ (or EF5 Beta), does this mean I have to expose a foreign key property on the dependent entity? When using the Fluent API? And when the DbContext is in a different project than the Entity?

I can't see any other way to do it. The DbModelBuilder needs to know the foreign key property in order to include it as part of the primary key. However if the property is not exposed, and the Entity & DbContext implementations are in different projects/libraries, there is no way to expose it (don't want to put InternalsVisibleTo on the entity lib).


回答1:


Identifying relationship always needs FK property exposed on the dependent entity because the property must be part of primary key - that is what makes it identifying. I didn't try it with DbContext but unless there is some internal issue / bug it should work.



来源:https://stackoverflow.com/questions/9571864/in-ef4-1-do-you-have-to-expose-a-foreign-key-property-on-a-dependent-entity-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!