0

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

Umair
  • 3,322
  • 2
  • 22
  • 38
  • For "dynamic ordering", I strongly suggest you to look at this : http://stackoverflow.com/questions/41244/dynamic-linq-orderby – Raphaël Althaus May 31 '13 at 21:57
  • I will have a look into this, though I also found out some better repository patterns for GetAll, Update, Delete, etc... Do you suggest any good pattern for this? Or any opensource library? Thanks again though. – Umair Jun 01 '13 at 18:07

0 Answers0