重複の可能性:
LINQ to Entities がメソッドを認識しない
Entity Framework 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()
(子 - 子カテゴリのコレクション) クエリを実行すると、次のエラー メッセージが表示されます。
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.
なぜ機能しないのですか?正しく書くには?