Why do navigation properties have to be public for a proxy to be created?

扶醉桌前 提交于 2020-03-22 08:04:26

问题


At http://msdn.microsoft.com/en-us/library/dd468057.aspx I read that all navigation properties for which I would like to have a change tracking proxy need to be public and virtual. From what I understand, the CLR creates subclasses of my POCOs dynamically, and it re-implements the properties to provide the requested behaviour.

For this I undertand that the property needs to be virtual, and that it should have protected or higher accesability. However, if I want to use these for convenience within the assemby, but don't want to expose them, I prefer them not to be public. Which leads me to two questions.

  1. (for my understanding of what is going on) why does the runtime require the properties to be public rather than protected or internal?

  2. (for my actual situation) are there any workarounds to hide the navigation property, but still have the change tracking behaviour?


回答1:


Properties must be public (and virtual) OR protected (and virtual) for proxies to work.

Proxies are not pre defined in your assembly, therefore internal won't work.

Private won't work for obvious reasons (proxies inherit from your classes).



来源:https://stackoverflow.com/questions/11082766/why-do-navigation-properties-have-to-be-public-for-a-proxy-to-be-created

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