I am trying to write a get all function and pass in where and order expression to get records for my paging grid view:
public virtual IList<Customer> GetAll(Expression<Func<Customer, bool>> orderClause, Expression<Func<Customer, bool>> whereClause, int takeItems, int skipItems, bool descendingOrder = false)
{
if (descendingOrder)
{
return Accessor.Current.WCDataClassesDataContext.Customers.AsNoTracking().OrderByDescending(orderClause).Where(whereClause).Skip(skipItems).Take(takeItems).ToList();
}
else
{
return Accessor.Current.WCDataClassesDataContext.Customers.AsNoTracking().OrderBy(orderClause).Where(whereClause).Skip(skipItems).Take(takeItems).ToList();
}
}
But I am getting error in the order clause that it can not convert from int to bool. After changing the bool in expression to object I still get an error:
If I access it like this:
GetAll(o => o.CustomerID, j => j.CustomerID != 20, 10, 0);
Error: "LINQ to Entities only supports casting EDM primitive or enumeration types"
Any suggestions for this error and how to resolve this?
Thanks