什么是缺点先关闭ProxyCreationEnabled为CTP5 EF code的 [英] What are the downsides to turning off ProxyCreationEnabled for CTP5 of EF code first

查看:275
本文介绍了什么是缺点先关闭ProxyCreationEnabled为CTP5 EF code的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的WCF服务可以从code第一个模型是通过设置 ProxyCreationEnable 使用下面的code。

The only way that my WCF service can return classes from a code first model is by setting the ProxyCreationEnable to false using the code below.

((IObjectContextAdapter)MyDb).ObjectContext.ContextOptions.ProxyCreationEnable = false;

什么是这样做的负面影响?一个收获是,我至少可以得到这些动态类型的系列化,以便能够在使用WCF的电线发送。

What are the negative consequences of doing this? One gain is that I can at least get these dynamic types serialized so they can be sent over the wire using WCF.

推荐答案

动态代理用于更改跟踪和懒加载。当WCF尝试序列化对象,相关方面通常是封闭的,但设置导航属性的序列化,将自动触发延迟加载(在关闭的情况下)=>​​例外。

Dynamic proxies are used for change tracking and lazy loading. When WCF tries to serialize object, related context is usually closed and disposed but serialization of navigation properties will automatically trigger lazy loading (on closed context) => exception.

如果您关闭延迟加载,你将需要使用预先加载您要使用所有的导航属性(包含上的ObjectQuery)。跟踪更改WCF它只能为其附加到ObjectContext的实体的修改不上工作。

If you turn off lazy loading you will need to use eager loading for all navigation properties you want to use (Include on ObjectQuery). Tracking changes doesn't work over WCF it works only for modification of entity which is attached to ObjectContext.

这篇关于什么是缺点先关闭ProxyCreationEnabled为CTP5 EF code的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆