I am using patterns mentioned here http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
And i am using method below to query EF
public virtual IEnumerable<TEntity> Get(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = "")
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
foreach (var includeProperty in includeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
if (orderBy != null)
{
return orderBy(query).ToList();
}
else
{
return query.ToList();
}
}
Now i want to create dynamic Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>
expression to order my data.
I know only field name as string and order type (ascending, descending) as string (asc, desc)
This is very late to the party but the correct answer is located on another question at https://stackoverflow.com/a/10935223/14275
finally i could write the method i want.
This method takes two parameters, first one field name other one is asc or desc. Result of method can be used directly with IQueryable object.
Thanks for your helps
I am not sure what exactly you want to accomplish, but I had changed your code and add some example to demonstrate how does it work.
This is a simple console app, which has dummyText as list. Queryable method enables to use filter and sort expression as you want. I hope it helps