Entity framework 4 实体框架4 IObjectSet包括

Entity framework 4 实体框架4 IObjectSet包括,entity-framework-4,Entity Framework 4,我首先使用的是EF4 CPT4代码,我已经设置了ObjectContext以返回IOObjectSet,这样我就能够模拟和测试我的repo。但是,我现在注意到,我无法像使用ObjectSet那样使用.Include()方法进行即时加载 有没有办法让这一切顺利 编辑: 我添加了这个扩展方法: public static IQueryable<TSource> Include<TSource>(this IQueryable<TSource> source, st

我首先使用的是EF4 CPT4代码,我已经设置了ObjectContext以返回IOObjectSet,这样我就能够模拟和测试我的repo。但是,我现在注意到,我无法像使用ObjectSet那样使用.Include()方法进行即时加载

有没有办法让这一切顺利

编辑: 我添加了这个扩展方法:

public static IQueryable<TSource> Include<TSource>(this IQueryable<TSource> source, string path)
{
    var objectQuery = source as ObjectQuery<TSource>;
    return objectQuery == null ? source : objectQuery.Include(path);
}
环境足迹小组的答复:

这是CTP4中的一个已知问题,Include是ObjectSet上的一个实例方法,但当您的集合被类型化为IOObjectSet时,实际上是在CTP4中包含的IQueryable上使用扩展方法。此扩展方法不适用于已编译的查询,但我们将在下一版本中尝试并支持此方法


~Rowan

你是如何调用Include方法的?也是在朱莉·勒曼(Julie Lerman)的新书中使用的扩展方法。仍然没有找到解决办法。这篇文章也有同样的问题:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[PostHope.Core.DomainObjects.SiteAnnouncement] Include[SiteAnnouncement](System.Linq.IQueryable`1[PostHope.Core.DomainObjects.SiteAnnouncement], System.String)' method, and this method cannot be translated into a store expression.