Serializable classes and dynamic proxies in EF – how?

If you want to serialize entities you can disable proxy creation before retrieving that object. You also need to eager load navigational properties if you want to serialize them as well.

To disable proxy creation in EF 4.1

dbContext.Configuration.ProxyCreationEnabled = false;

In EF 4

objectContext.ContextOptions.ProxyCreationEnabled = false;

eg:

var users = context.Users.Include("Claims").Where(/**/);

Leave a Comment