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