【发布时间】:2012-08-29 23:26:19
【问题描述】:
我使用实体框架 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);
}
这很好用:
var cat=Context.Categories.Active().ToList()
但我需要在 Select 中使用此扩展方法。 看简化查询:
return Context.Categories
.Select(c => new { Children=c.Children.AsQueryable().Active()})
.ToList()
(Children - 子类别的集合) 执行查询时,我收到一条错误消息:
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.
为什么不工作?如何正确书写?
【问题讨论】:
-
确实有thousands 的问题与此错误消息有关。
-
我猜你没有仔细阅读这个问题。出现此错误消息的原因有多种。
-
如果您阅读了您发送的内容,您自己就明白了。
-
这个错误信息每次出现的原因都是一样的。
-
我认为你对这个主题并不精通。
标签: linq entity-framework entity-framework-4 iqueryable