Water Cooler v2
Water Cooler v2

Reputation: 33880

Can we have non-proxy POCO's and POCO proxies in the same ObjectContext?

Can I have a POCO that I don't want proxy to be generated for (so I don't set its properties virtual) and another POCO for whom I want a proxy to be generated (properties virtual) managed by the same ObjectContext against the same EDM in a single project?

If I set the ObjectContext.ContextOptions.ProxyCreationEnabled to true and have one of the POCO's only have it properties as virtual, will the Entity Framework create a proxy only for one and leave the other untouched even if I used CreateObject<T> on both?

Upvotes: 1

Views: 273

Answers (1)

Slappy
Slappy

Reputation: 4092

I am going to go out on a limb here and say no, not based on anything other than how most mocking frameworks create dynamic proxies. At runtime the DataContext will create a proxy class inherited from your POCO. If nothing is virtual then it will provide no data support. I suspect it will notify you of this with an exception, but am not sure.

Why would you want EF to manage a simple class? There is nothing to manage. Sounds like you are trying to use EF as a stock standard factory class. Perhaps you could provide some context in the question?

Upvotes: 1

Related Questions