Search code examples
entity-frameworkwcfentity-framework-6dynamic-proxy

WCF and with DynamicProxies


I have a service that use EF 6.1.3 to access to the database. I have POCO entities to store the results of EF, but the resutls are dynamicProxies instead of the POCO entity.

The problem is that when the service try to send to the client this dynamic proxy, I get an error receiving the http response.

I have tried to disabled the creation of the proxies entities in my dbContext, and then I receive my real POCO entity so I have no problems.

But really I don't know what is dynamic proxies and when is usuful to use them and when I can disabled them.

EDIT: I have disabled lazy loading.

Thanks.


Solution

  • When creating instances of POCO entity types, the Entity Framework often creates instances of a dynamically generated derived type that acts as a proxy for the entity. This proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed. For example, this mechanism is used to support lazy loading of relationships.

    Source: https://msdn.microsoft.com/en-us/data/jj592886.aspx

    You will find everything you need in the above article!