简体   繁体   English

POCO / PROXY禁用延迟加载

[英]POCO/PROXY Disabling Lazy Loading

In the book " Entity Framework 4 in Action ", in section 16.1.3 and again in 16.2.4, it is stated 在第16.1.3节以及第16.2.4节“ 行动中的实体框架4 ”一书中对此进行了说明。

If you have a proxy instance, remember to disable lazy loading before serializing, or you'll end up sending unwanted data to the client. 如果您有代理实例,请记住在序列化之前禁用延迟加载,否则最终将不必要的数据发送到客户端。

However, the authors never say how to disable lazy loading. 但是,作者从未说过如何禁用延迟加载。 In my own searches, I've heard of ContextOptions.LazyLoadingEnabled. 在我自己的搜索中,我听说过ContextOptions.LazyLoadingEnabled。 Is that "the way" this is done? 是这样的“方式”吗? Is there more than one way (besides disabling proxy generation)? 有不止一种方法(除了禁用代理生成)?

I read in one article that the LazyLoadingEnabled flag only pertains to EntityObject entities, not POCO entites: 我读过一篇文章 ,其中LazyLoadingEnabled标志仅适用于EntityObject实体,不适用于POCO实体:

Turning lazy loading off will now allow your classes to be serialized properly. 关闭延迟加载现在将允许您的类正确序列化。 Note, this is if you are using the standard Entity Framework classes. 注意,这是在使用标准实体框架类的情况。 If you are using POCO, you will have to do something slightly different. 如果您使用的是POCO,则必须做一些稍有不同的事情。

With POCO, the Entity Framework will create proxy classes by default that allow things like lazy loading to work with POCO. 使用POCO,默认情况下,实体框架将创建代理类,从而允许像延迟加载这样的事情与POCO一起使用。 This proxy basically creates a proxy object that is a full Entity Framework object that sits between the context and the POCO object. 此代理基本上创建一个代理对象,该对象是位于上下文和POCO对象之间的完整的Entity Framework对象。 When using POCO with WCF (or any serialization) just turning off lazy loading doesn't cut it. 当将POCO与WCF(或任何序列化)一起使用时,仅关闭延迟加载不会削减它。 You have to turn off the proxy creation to ensure that your classes will serialize properly 您必须关闭代理创建以确保您的类将正确序列化

I suspect the above commentary is simply erroneous. 我怀疑以上评论简直是错误的。

Yes, ContextOptions.LazyLoadingEnabled is "the way." 是的, ContextOptions.LazyLoadingEnabled是“方法”。 The serialization issue is related, but different. 序列化问题是相关的,但有所不同。 Proxies have a different runtime type. 代理具有不同的运行时类型。 That can mung serialization. 那会导致序列化。 The only relation to lazy loading is that pure (non-proxy) POCOs don't do lazy loading. 与延迟加载的唯一关系是纯(非代理)POCO不会进行延迟加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 推销EF实体; 禁用代理创建和延迟加载? - seralizing EF entities; disabling Proxy Creation and Lazy Loading? 延迟加载不适用于Entity Framework中的POCO类 - Lazy loading not working for POCO classes in Entity Framework EF 5.0数据库优先,POCO类型和延迟加载 - EF 5.0 Database first, POCO types and Lazy Loading EF6中的延迟加载未填充POCO中的相关实体列表 - Lazy Loading in EF6 not populating related list of entities in a POCO 我的库中的延迟加载或代理模式 - Lazy loading or proxy pattern in my library 为什么禁用延迟加载会导致相关表没有结果? - Why does disabling lazy loading cause related tables to have no results? 如何在不使用实体框架的情况下设计DAL / BAL以支持使用POCO进行延迟加载 - How to design DAL/BAL to support Lazy loading using POCO without using Entity framework 在 dapper 中可以延迟加载吗? 泛型 (POCO) 和动态 API 之间有什么区别? - Is lazy loading possible in dapper? And what is the difference between the generic (POCO) and dynamic API? 带有延迟加载的EF4 POCO。 为什么fixup迭代整个数据库? - EF4 POCO with Lazy Loading. Why does fixup iterate entire database? 延迟加载不在Entity Framework中。 (未创建代理) - Lazy Loading not working in Entity Framework. (Proxy not being created)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM