Probably a question with a silly answer but: is there a way to define an IQueryable and then reuse it in different contexts afterwards?
Somethink like (Pseudocode):
public IQueryable<myItem> MyQuery()
{
using(MyContext context = new MyContext())
{
return (from myItem in context.MyItems
select ...);
}
}
That is going to be used in a 'some' way as below.
public void MyMethod()
{
using(MyContext context = new MyContext())
{
context.ExecuteQueryUnderContext(MyQuery());
}
using(MyContext context2 = new MyContext())
{
context2.ExecuteQueryUnderContext(MyQuery());
}
}
Thanks
I would pass the context as a parameter for your Query method
public IQueryable<myItem> MyQuery(MyContext context)
{
return (from myItem in context.MyItems
select ...);
}
public void MyMethod()
{
using(MyContext context = new MyContext())
{
var query = MyQuery(context);
}
}