Entity Framework Lazy Loading in .NET 3.5

為{幸葍}努か 提交于 2019-12-10 06:58:14

问题


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?


回答1:


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:

Examples:

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



来源:https://stackoverflow.com/questions/5216251/entity-framework-lazy-loading-in-net-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!