Question: I have been reading posts about `Expression<Func<TModel,TResult>>` for about an hour and I really do not understand this. My apologizes, but I just don't. 

I have an issue that I have a abstract class that has a call to EF6 where I need to order by some property that I would like to define in the child class. That said I will add an example below.

```
public abstract MyController<TModel>:ApiController
{
     protected IRepository<TModel> Repository {get;}

     protected MyController(IRepository<TModel> repo)
     {
         Repository = repo;
     }

     protected Expression<Func<TModel,TResult>> OrderBy {get; set}

     public IHttpActionResult GetItems()
     {
        return Ok(Repository.Get().OrderBy(x=>OrderBy(x)).ToList()); //with lots of other cool stuff.
     }

}

public PersonController:MyController<Person>
{
    public PersonControler(IRepository<Person> repo):base(repo)
    {
        OrderBy = //I need help here
    }   

}

```

Okay, so after all of this I have been reading about Expressions and I do not understand why `OrderBy = (person)=> person.LastName` will not work here. Can someone please explain how the Expression works and how to make this work?

Answer: 
Declare your property as

```
protected Expression<Func<TModel, object>> OrderBy { get; set; }

```

Assign it in `PersonController`

```
OrderBy = p => p.LastName

```

And use it like

```
Repository.Get().OrderBy(OrderBy).ToList()

```
Under the hood (of EF/LINQ query translation engine) `Expression` (actually all methods call chain) is translated to SQL query. There is expression visitor (see pattern 'visitor'), which does the job.

To get things work:  

method `Get` of `IRepository` should return type `DbSet<TModel>` (for EF) or `Table<TModel>` (for LINQ to SQL)  

type of ordering key should be defined either in abstract class (`public abstract MyController<TModel, TKey> : ApiController`) or in expression directly (`protected Expression<Func<TModel, int>> OrderBy {get; set}`)