问题
I am paging and sorting a GridView
which uses ObjectDataSource
. The ObjectDataSource
gets data from a List in my business layer, and this List is populated by an IEnumerable<Type>
in my data layer which uses the Entity Framework.
The guts of the paging and sorting is done in the data layer, as follows:
var customers = (from c in entities.Customers
select c).OrderBy(sortParameter).Skip(startRowIndex).Take(maximumRows));
As you can see, I am passing parameters from the ObjectDataSource
to decide how any records need to be returned, and from which position, to control the paging and sorting.
This all works fine.
My problem is that I need to sort by a field that does not exist in the database table. It is a calculated field that is added in my business layer (the List). (This calculated field is a Customer name that is looked up in a DLL based on Customer ID
in my database).
I was hoping to keep the sorting and paging logic in the database layer, but cannot find a neat way to do this. Should I be paging and sorting in the business layer instead (this is a List). If so, can anyone give me some tips how I can add similar paging and sorting to my List that currently exists in my data layer. (i.e. I am only looking to return the rows from my database that are needed for the current page of the GridView
).
Thanks for any help, and kindly let me know if I can explain this more clearly!
来源:https://stackoverflow.com/questions/22404307/gridview-sorting-and-paging-entity-framework-with-calculated-field