The problem is here: -
s => s.GetType().GetProperty(sortField)
When you try to access the IQueryable result set, it translates to SQL and the query runs against your database (rather than running in memory). The problem is that, obviously, your database does not know anything about your types, cannot call any methods on them and, of course, cannot reflect them.
You will need to create your own expression tree that can be translated into SQL. The API expression is quite complex and you will need to read a little if you really want to get it. Here's a good starting point when creating dynamic queries using an API expression for you .
Fortunately, your specific case is quite simple and there are examples of it here , here and here , but I really recommend you read a little to understand what is happening. If you just copy-paste, then you or someone else will have to support it and have a very sad time.
source share