あなたのコンテキストクラスは ABC Entitiesと呼ばれているため、これは Entity Framework であると想定しています。
コンパイルされたクエリデリゲートを保持するプライベート静的フィールドを作成し、CompiledQuery.Compile()
メソッドを使用して初期化します(簡潔にするためにフィールド初期化子でこれを行うことにしました...静的コンストラクターで行うことも、最初の場合は遅延して行うこともできました呼ばれるなど)。次に、 が呼び出されたときにデリゲートを呼び出しGetAllItems()
ます。
private static Func<ABCEntities, IQueryable<Item>> _activeItemsQuery =
CompiledQuery.Compile<ABCEntities, IQueryable<Item>>(
(pos) => pos.Items.Where(o=>o.Is_Inactive==false));
public IList<Item> GetAllItems()
{
using (var pos = new ABCEntities())
{
return _activeItemsQuery(pos).ToList();
}
}
EF コンパイル済みクエリの詳細については、http: //msdn.microsoft.com/en-us/library/bb896297.aspxを参照してください。
また、その拡張メソッド構文を使用する場合は必要ないため、 from
andも削除しました。select
私は代わりに行うことができました:
private static Func<ABCEntities, IQueryable<Item>> _activeItemsQuery =
CompiledQuery.Compile<ABCEntities, IQueryable<Item>>(
(pos) => from itm in pos.Items where itm.Is_Inactive == false select itm;
しかし、個人的には、ほとんどの場合、拡張メソッドを使用することを好みます。