1

I want to do this:

var test = SqlCompact("OrderID", "ASC")

So this should sort the following join query by order ID:

var result = (from od in orders
        join em in employees on od.EmployeeID equals em.EmployeeID
        join ct in customers on od.CustomerID equals ct.CustomerID
        //orderby em.EmployeeID
        select new
        {
            od.OrderID,
            od.ShipCountry,
            ct.CompanyName,
            ct.ContactName,
            FullName = em.FirstName + ' '+ em.LastName, 
        }).ToList();

My attempt:

var result2 = result.ToList();
if (sort == "OrderID"){
 result2 = result.OrderBy("OrderID");
}

But I get the error:

'System.Collections.Generic.List' does not contain a definition for 'OrderBy' and the best extension method overload 'System.Linq.Dynamic.DynamicQueryable.OrderBy(System.Linq.IQueryable, string, params object[])' has some invalid arguments

1 Answers1

1

How about this

var result2 = result.ToList();
if (sort == "OrderID"){
 result2 = result.OrderBy(x=>x.OrderID).ToList();
}
Sateesh Pagolu
  • 9,282
  • 2
  • 30
  • 48
  • Then I get an error with returning result2. For `return result2;`. I get the following error: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' – user3521029 Oct 13 '15 at 00:31
  • @user3521029 : at which line? – Sateesh Pagolu Oct 13 '15 at 00:36
  • Oh sorry I forgot to write my whole SqlCompact function. But basically I want to return result2 to the main method. That's where I get that error. – user3521029 Oct 13 '15 at 00:43
  • @user3521029 : please add function code. Ensure your return type of the function and result2's datatype match. If not, cast it. – Sateesh Pagolu Oct 13 '15 at 00:45