I have created a function that has the follwing parameter:
List>> orderBy = null
T
foreach (Expression<Func<CatalogProduct, bool>> func in orderBy)
{
catalogProducts = catalogProducts.OrderBy(func);
}
This will be OK.
try this
IOrderedQueryable temp = null;
foreach (Expression<Func<CatalogProduct, bool>> func in orderBy)
{
if (temp == null)
{
temp = catalogProducts.OrderBy(func);
}
else
{
temp = temp.OrderBy(func);
}
}
Two problems; firstly, ThanBy
should be ThenBy
; secondly, ThenBy
is only available on the generic type, IOrderedQueryable<T>
.
So change to:
IOrderedQueryable<CatalogProduct> temp = null;
foreach (Expression<Func<CatalogProduct, bool>> func in orderBy) {
if (temp == null) {
temp = catalogProducts.OrderBy(func);
} else {
temp = temp.ThenBy(func);
}
}
and you should be sorted.