I got this error when trying to sort any columns that are not in the Order table, if I use OrderBy("Customer.CompanyName" + " " + sortDir)
the error will gone but all the columns will become unable to sort. The OrderBy
method used below come from here.
What is the cause of the problem ?
public ActionResult WebGrid(int page = 1, int rowsPerPage = 10, string sortCol = "OrderID", string sortDir = "ASC")
{
List<Order> res;
using (var nwd = new NorthwindEntities())
{
var _res = nwd.Orders
.OrderBy(sortCol + " " + sortDir)
.Select(o => new Order
{
OrderID = o.OrderID,
OrderDate = o.OrderDate,
CompanyName = o.Customer.CompanyName,
FirstName = o.Employee.FirstName,
//......
//......
//......
});