patterncsharpCritical
LINQ Orderby Descending Query
Viewed 0 times
orderbylinqdescendingquery
Problem
I have a LINQ query that I want to order by the most recently created date.
I tried:
I have also tried:
but this gives an error :
From what I've read, the first way it should work. I've tried changing
What am I doing wrong?
I tried:
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, the first way it should work. I've tried changing
descending to ascending just to see if it does anything but it stays the same.What am I doing wrong?
Solution
You need to choose a Property to sort by and pass it as a lambda expression to
like:
Really, though the first version of your LINQ statement should work. Is
OrderByDescendinglike:
.OrderByDescending(x => x.Delivery.SubmissionDate);Really, though the first version of your LINQ statement should work. Is
t.Delivery.SubmissionDate actually populated with valid dates?Code Snippets
.OrderByDescending(x => x.Delivery.SubmissionDate);Context
Stack Overflow Q#5344805, score: 779
Revisions (0)
No revisions yet.