System.Data.Entity.DynamicProxies……不能序列化

来源:互联网 发布:淘宝店铺怎么彻底关闭 编辑:程序博客网 时间:2024/05/28 15:47

问题:

序列化时,返回错误:类型为“System.Data.Entity.DynamicProxies.……………………………………………………”的对象不能序列化

 

解决方案:

EF的DBContext做如下设置:

dbContext.Configuration.ProxyCreationEnabled = false;

 

参考:

DbContext.Configuration:

http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext.configuration(v=vs.113).aspx

DbContextConfiguration:

http://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration(v=vs.113).aspx

Public propertyLazyLoadingEnabledGets or sets a value indicating whether lazy loading of relationships exposed as navigation properties is enabled. Lazy loading is enabled by default.Public propertyProxyCreationEnabledGets or sets a value indicating whether or not the framework will create instances of dynamically generated proxy classes whenever it creates an instance of an entity type. Note that even if proxy creation is enabled with this flag, proxy instances will only be created for entity types that meet the requirements for being proxied. Proxy creation is enabled by default.

 

0 0
原创粉丝点击