LINQ Orderby Descending Query
Asked 07 September, 2021
Viewed 2.2K times
  • 56
Votes

I'm sure this will be a relatively simple one.

I have a LINQ query that I want to order by the most recently created date.

See:

        var itemList = from t in ctn.Items
                        where !t.Items && t.DeliverySelection
                        orderby t.Delivery.SubmissionDate descending
                        select t;

I have also tried:

       var itemList = (from t in ctn.Items
                        where !t.Items && t.DeliverySelection
                        select t).OrderByDescending();

but this gives an error :


  

No overload for method 'OrderByDescending' takes 0 arguments

From what I've read, I'm fairly sure the first way I've done it should work. I've tried changing descending to ascending just to see if it does anything but it stays the same.

I'd be grateful if someone could take a look at the query and see if I'm doing anything wrong. Thanks :)

4 Answer