I have a list of customer and i need to sort and group the list according to business rule.
- Group by Customer Name
- Sort by Customer Name in alphabetical order
- if there are several results for the same name, then they need to sorted by date of birth in ascending order (the oldest is listed first)
Below is the entity.
public class Customer
{
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime DateofBirth {get; set;}
}
Thanks in advance.
customers.GroupBy(c => c.FirstName)
.Select(c => c.OrderBy(c => c.FirstName).ThenBy(c => c.LastName));