Serializable classes and dynamic proxies in EF - how?

前端 未结 5 477
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 12:08

In [a previous posting], I was set on the path to having to clone my entities. This I\'ve attempted to do with a serialisation approach as found in [codeproject].

b

5条回答
  •  孤街浪徒
    2020-11-29 12:48

    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(/**/);
    

提交回复
热议问题