I am trying to sort a set of Users. I have access to the sorting property and direction (asc, desc). My current order by query is below. But as you can see it doesn't account for the sort direction. How do can I build this expression without having to use Dynamic Linq, or adding another set of statements for "asc" or "desc" sort direction.
public override IQueryable<DalLinq.User> GetSort(IQueryable<DalLinq.User> query) {
//SelectArgs.SortDirection <- Sort Direction
switch (SelectArgs.SortProperty) {
case "LastName":
query = query.OrderBy(p => p.LastName);
break;
case "FirstName":
query = query.OrderBy(p => p.FirstName);
break;
default:
query = query.OrderBy(p => p.UserName);
break;
}
return query;
}