I have a query:
public IQueryable GetOrder(int id)
{
using (Context = new MyEntities())
{
IQueryable query = Context.Orders
.Include("Customers")
.Include("Products")
.Include("OrderLines")
.Where(o => o.OrderID == id);
return query;
}
}
Now, I want to extract the basic query (everything sans the .Where
clause) so I can reuse it in other methods. I tried this:
private IQueryable GetIncludes(MyEntities context)
{
return context.Orders
.Include("Customers")
.Include("Products")
.Include("OrderLines");
}
public IQueryable GetOldOrders()
{
using (Context = new MyEntities())
{
DateTime ninetyDaysAgo = new DateTime(DateTime.Now.AddDays(-90));
IQueryable query = GetIncludes(Context);
query = query.Where(o => o.OrderDate < ninetyDaysAgo);
return query;
}
}
but the compiler tells me it Cannot convert lambda expression to type 'string' because it is not a delegate type
.
I looked at Cannot convert lambda expression to type 'string' because it is not a delegate type and can report that I am using System.Linq
(and System.Linq.Dynamic
) and System.Data.Entity
. System.Data.Entity
is greyed out in VS.
How do I create an IQueryable
that I can add a .Where
clause to after it's created?