Use Expression Descriptors
This help article will show you how to create generic expression descriptors (SortDescriptor
Sorting
You can order your data items by the result of a complex calculation without having to expose it through a read-only property. All you need to do is to use the new SortDescriptor
Example 1: Create a generic SortDescriptor
var descriptor = new SortDescriptor<Employee, double>
{
SortingExpression = e => e.Orders.SelectMany(o => o.Details).Sum(d => d.UnitPrice * d.Quantity),
SortDirection = ListSortDirection.Descending
};
For more information you can check the Sorting section
Grouping
You can also group objects by the result of an equally complex operation:
Example 2: Create a generic GroupDescriptor
var descriptor = new GroupDescriptor<Employee, int, int>
{
GroupingExpression = e => e.Orders.Where(o => o.Details.Any(d => d.Product.ProductName.Contains("Syrup"))).Count(),
SortDirection = ListSortDirection.Ascending
};
For more information you can check the Grouping section
Filtering
The new FilterDescriptor
Example 3: Create a generic FilterDescriptor
var descriptor = new FilterDescriptor<Employee> { FilteringExpression = e => prospects.Contains(e) };
For more information you can check the Filtering section