Using Include in Entity Framework 4 with lambda expressions

后端 未结 3 1643
时光取名叫无心
时光取名叫无心 2020-11-30 22:26

I\'ve seen many articles about how to overcome this matter, all related to CTP4, Or adding my own extension methods.

Is there an \"official\" EF4 included way to use

3条回答
  •  温柔的废话
    2020-11-30 22:46

    The RTM version of Entity Framework 4.1 actually includes extension methods in the EntityFramework.dll file, for eager loading with lambda through the Include function. Just include the DLL in your project and you should be able to write code like:

    var princesses1 = context.Princesses.Include(p => p.Unicorns).ToList();
    

    Remember to add an Import/Using statement to include the System.Data.Entity namespace. Otherwise the compiler cannot find the extension methods. E.g:

    using System.Data.Entity;
    

    See this ADO.NET team blog article for more information.

提交回复
热议问题