Geeks With Blogs

Create Fun Things - Samer's Developer Blog Development Blog for C#, .NET and Obj-C

The other day I required ordering a list of people first by the date they were created, and then by their last name. I spent forever trying to find out why my two OrderBy statements were conflicting with one another, until I remembered you use “ThenBy()” for any additional sorting you want to do.

So the query looked something like this then:

IEnumerable<Person> myPersons = myDataContext.Persons
.OrderBy(m=>m.DateCreated)
.ThenBy(m=>m.LastName);

 

Just thought I’d share! It’s easy to forget all the useful LINQ methods, like I did.

Posted on Wednesday, July 29, 2009 3:56 PM "It's that easy" | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Quick Tip: LINQ OrderBy and ThenBy

# re: Quick Tip: LINQ OrderBy and ThenBy
Requesting Gravatar...
Thanks for for the Info Samer
Left by Supersum on Oct 29, 2009 4:13 PM

# re: Quick Tip: LINQ OrderBy and ThenBy
Requesting Gravatar...
Thanks, I was losing my time in trying to put several OrderBy !
Left by Gérard on Jun 26, 2012 10:16 AM

Your comment:
 (will show your gravatar)


Copyright © samerpaul | Powered by: GeeksWithBlogs.net