As the error message says, one of the properties you're trying to return is defined as an
int
, and can't be implicitly converted to a
string
. I would suspect either
OrderID
,
CustomerID
, or both.
You'll need to add a
.ToString()
call to the
int
property.
c.OrderID.ToString()
It would probably also be better to move the conditional access
outside of the
Func
, so that you only evaluate it once:
Func<Order, string> orderingFunction;
if (sortColumnIndex == 1 && isIdSortable)
{
orderingFunction = c => c.OrderID.ToString();
}
else if (sortColumnIndex == 2 && isNameSortable)
{
orderingFunction = c => c.CustomerID.ToString();
}
else if (sortColumnIndex == 3 && isAddressSortable)
{
orderingFunction = c => c.ShipAddress;
}
else if (sortColumnIndex == 4 && isTownSortable)
{
orderingFunction = c => c.ShipCountry;
}
else
{
orderingFunction = c => string.Empty;
}