Entity Framework 6.1.1 ignores ProxyCreationEnabled settings

448 views Asked by At

I have a context class, and at some point I need to get data from database in my POCO classes, so that I can serialize that data and send over to my web service. I do not want to deserialize proxies on the other end, but I am not able to force EF to create my POCO classes.

I am using following code to retrieve data:

((IObjectContextAdapter) this).ObjectContext.ContextOptions.ProxyCreationEnabled = false;
var nodes = (from node in TreeNodes select node).ToList();
((IObjectContextAdapter)this).ObjectContext.ContextOptions.ProxyCreationEnabled = true;

Note that TreeNodes is a TPH and base class is abstract. Is there a way to get POCO classes in my case?

1

There are 1 answers

0
DarkDeny On BEST ANSWER

I solved this scenario by instantiating same context again, settings configuration, and then run the query and disposing context.