What causes POCO proxy entities to only sometimes be created in Entity Framework 4

不羁的心 提交于 2019-12-08 05:37:59

问题


I have set up my POCOs and I have marked their public properties as virtual and I am successfully getting Proxies most of the time (95%) but randomly I am getting EF return some proxies and some non-proxies.

Recycling the app pool when this happens will then fix this instance of the error and it will go away for an amount of time. Then it will re-occur in some other random (it seems) place.

What can cause this sort of behaviour?

alt text http://www.freeimagehosting.net/uploads/36c95af3c7.jpg

Thanks, Kohan


回答1:


Solved it (im getting in the habit of almost giving up, posting here and then solving it)

Anyway, when I was adding a new Question i was using something like var q = new Question() this was then being stored as a non-proxy. In the end i found out by creating a new Question on the ObjectContext like so var q = ObjectContext.CreateObject<Question>(); causes it to be a proxy and works just fine and dandy.

Hope this helps someone,
Cheers,
Kohan.

A helpful source : http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx (read the comments)



来源:https://stackoverflow.com/questions/3044378/what-causes-poco-proxy-entities-to-only-sometimes-be-created-in-entity-framework

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