Lets say that I need to execute this query with EF in business layer
var list = context.Invoices.Select(x => new
{
InvoiceNumber = x.InvoiceNUmber,
InvoiceDate = x.InvoiceDate,
CustomerName = x.Customer.CustomerName,
TotalValue = x.InvoiceData.Sum(y => y.Quantity * y.Price),
Id = x.Id
}).ToList();
What can I do for this list to be easily sortable, searchable or filterable in UI layer?
Thanks,
Goran
The way to do it is to return a object that is not anonymous. That is, create a class to hold this data. It should either have an implicit zero-argument constructor (because you have no constructors), or an explicit zero-argument one (because you have defined other constructors). Then you can say:
Now you can return the strongly-typed list of objects out of your business layer, and your UI layer can use LINQ (or whatever) to do sorting/filtering/paging.