2
我首先使用EF4 CPT4代码,并且我已经设置了我的ObjectContext以返回IObjectSet,因此我可以模拟和测试我的回购。但是,我现在注意到,我无法使用.Include()方法进行加载,就像我可以使用ObjectSet一样。实体框架4 IObjectSet包括
有没有办法让这个工作?
编辑: 我添加了这个扩展方法:
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);
}
而且它并添加include()方法,但是现在我得到这个错误:
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.
你是怎么调用Include方法的? – Jonathan 2010-10-04 23:26:35
从扩展方法(来自Julie Lerman的博客http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/)也在她的新书中。还没有找到解决方案。这篇文章是相同的问题:http://stackoverflow.com/questions/2655886/iobjectset-include-extension-method-errors-with-compiledquery – Paul 2010-10-05 17:22:02