I am using the Entity Framework 4.1 with POCO entities in a new project. Everything was working fine until I began caching the entities using AppFabric Caching. I started getting erros retrieving the entitis from the cache related to deserializing the proxy objects. I fixed this problem by setting ContextOptions.ProxyCreationEnabled = false. The issue now is when I get entities back from the cache, I have to attach the entity to the current context using ObjectSet.Attach(entity) and add them to the state manager using ObjectContext.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified).
My question is is there a way to programmatically enable/disable the proxy for a set of entities? Or in other words a way to wrap the deserialized entity in the proxy object.
If there is not a good way to do this, is the way I am doing it now correct? Or is there a better way?