0

im working with EF codefirst and i need to sort the list of entries, i tried but could not find how to solve this task:

Lets say we have expression

thelist.orderby(p=> p.Name)

Question is : How to pass string instead of "p.Name" in case if i want to order list by p.Age for example

Because there are like 20 or more options to sort so im trying to shrink the code

TGIO
  • 523
  • 8
  • 19
  • http://msdn.microsoft.com/en-us/library/bb383982.aspx is it the right way ? – TGIO Dec 11 '12 at 18:59
  • http://stackoverflow.com/questions/3752305/declaring-funcin-t-out-result-dynamically/3753377#3753377 – TGIO Dec 11 '12 at 20:07

1 Answers1

0

Just install Dynamic LINQ (NuGet source), include using System.Linq.Dynamic; with your namespaces, and you'll be able to call:

thelist.OrderBy("Name");
thelist.OrderByDescending(someStringParameter);

etc.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154