可能重复:
LINQ to Entities does not recognize the methodEF IQueryable的扩展方法选择不工作
我使用实体框架4.3
我写的扩展方法:
public static IQueryable<TSource> Active<TSource>(this IQueryable<TSource> source) where TSource : class, IStatusable
{
return source.Where(s => s.Status == (int)StatusEnum.Enabled);
}
氏s的作品不错:
var cat=Context.Categories.Active().ToList()
但我需要在选择使用此扩展方法。 看简化查询:
return Context.Categories
.Select(c => new { Children=c.Children.AsQueryable().Active()})
.ToList()
(儿童 - 儿童类别的集合) 当查询执行我得到一个错误信息:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[Portal.FrontOffice.Model.Category] Active[Category](System.Linq.IQueryable`1[Portal.FrontOffice.Model.Category])' method, and this method cannot be translated into a store expression.
为什么不起作用?如何正确书写?
有literaly [上千](http://stackoverflow.com/search?q=LINQ+to+Entities+does+not+recognize + +方法+)与此错误消息的问题。 –
我想你不会仔细阅读这个问题。 此错误消息出于各种原因。 – DeeRain
如果你阅读你发送的内容,你自己就明白了。 – DeeRain