本文介绍了实体框架延迟加载在.NET 3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于服务器的限制,我仅限于NET 3.5的,我用的是延迟加载使用LINQ到SQL,但已经转而使用实体框架。 L2E没有延迟加载在3.5,而L2S一样。有没有一种方法来重新生成模板以某种方式来实现这一目标?

Due to server restrictions I am limited to .Net 3.5, I was using lazy loading with Linq to SQL but have since switched to the Entity Framework. L2E does not have lazy loading in 3.5 while L2S did. Is there a way to regenerate the templates somehow to achieve this?

推荐答案

您必须在EF 1显式调用加载方法/ .NET 3.5。

You have to explicitly call a load method in EF 1 / .NET 3.5.

所以,你访问未加载相关的集合或实体之前,你必须调用是这样的:

So, before you access a related collection or entity that is not loaded, you have to call something like:

例如:

if (!person.Pets.IsLoaded)
    person.Pets.Load();
if (!person.Address.IsLoaded)
    person.Address.Load();

当然,它是如此的丑陋,但这是它是如何工作的那个版本。

Of course it's so ugly, but this is how it worked in that version.

这是微软的博客在这里更多细节:

More details from Microsoft Blogs here:

http://blogs.microsoft.co.il/blogs/idof/archive/2008/08/20/entity-framework-and-lazy-loading.aspx

这篇关于实体框架延迟加载在.NET 3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:30