linq to sql how to retrieve most recent records based on datetime

List<CustomersList> thisList  = linqProvider.All<Customer>().Take(20).ToList<Customer>();

The customer table has a datetime field and I want to get the 20 most recent records.  How can I do that?
Who is Participating?
Alfred A.Connect With a Mentor Commented:
Try something like this:

List<CustomersList> thisList  = linqProvider.All<Customer>().OrderByDescending(x => x.YourDateField).Take(20).ToList<Customer>();

 var q = from c in db.Contact
           where c.DateOfBirth.AddYears(35) > DateTime.Now
           orderby c.DateOfBirth descending
           select c;

Open in new window

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
just use order by datetime field and get 20 records
ToString1Author Commented:
So will order by get the most recent?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.