0

I am passing in a query string that specifies a property to sort on but need to translate that to a property value in a model.

public class A
{
   public int Prop1 {get; set;}
   public int Prop2 {get; set;}
}

query string segment sort=Prop1

Server Side Code query is a IQueryable


query.OrderBy(x => x.{properyName})

I have parsed the property name value from the query string but now I need to translate that to x.Prop1 in the orderby lambda not sure a great way without using reflection

Hizzy
  • 741
  • 7
  • 27
  • If you're trying to extract parts of the uri https://stackoverflow.com/questions/29992848/parse-and-modify-a-query-string-in-net-core – Jasen Apr 11 '19 at 17:40
  • 1
    Why use reflection? just do a `switch (sort) { case "prop1": query = query.OrderBy(x => x.Prop1); break; }` – trashr0x Apr 11 '19 at 17:43
  • I can get the parts from the Uri. I like that thanks man – Hizzy Apr 11 '19 at 17:43

0 Answers0