I'm writing some kind of querybuilder and I need your help.
I have an OrderBy class with 2 Properties:
public class Order
{
public string OrderColumn { get; set; }
private bool _sortDesc = false;
public bool SortDesc
{
get { return _sortDesc; }
set { _sortDesc = value; }
}
}
Then I put some of these in a collection:
ObservableCollection<Order> OrderBys = new ObservableCollection<Order>()
{
new Order () {OrderColumn = "Nbr", SortDesc = false},
new Order () {OrderColumn = "Name", SortDesc = true}
}
Then I have my EntityCollection where I want to apply the orderBys:
ObservableCollection<MyEntity> Entities = EntitiesFormAnyWhere;
foreach (var orderBy in OrderBys)
{
This is where the magic should happen.
}
Any ideas?
EDIT:
public class MyEntity
{
public int Nbr {get;set;}
public string Name {get;set;}
public string Version {get;set;}
public string X {get;set}
}
I want to do something like this:
Entities.OrderBy(e => e.Nbr)
.ThenByDescending(e => e.Name)
But in an dynamic way.
P.S: Is this really a duplicate?