Hi,
i am asking if it is technically possible to use server side paging, sorting together with grouping using the kendo grid extension methods. I successfully implemented a repository that is executing a DataSourceRequest on an queryable sequence.
private
PagedListResult<T> BuildResult(SearchQuery<T> searchQuery, IQueryable<T> sequence)
{
var resultCount = sequence.Count();
// Filter
sequence = (IQueryable<TEntity>)sequence.Where(
this
.FilterDescriptors);
var result = (searchQuery.Take > 0)
? (sequence.Skip(searchQuery.Skip).Take(searchQuery.Take).ToList())
: (sequence.ToList());
var hasNext = (searchQuery.Skip > 0 || searchQuery.Take > 0) &&
(searchQuery.Skip + searchQuery.Take < resultCount);
return
new
PagedListResult<T>
{
Entities = result,
HasNext = hasNext,
HasPrevious = (searchQuery.Skip > 0),
Count = resultCount
};
}
I tried to add grouping as well, but i cannot find a way how to handle it. There is an extension method that looks pretty:
public
override
IQueryable<TEntity> ApplyGroups(IQueryable<TEntity> sequence)
{
if
(
this
.GroupDescriptors.Any())
{
var queryable = sequence.GroupBy(
this.GroupDescriptors);
return
(IQueryable<TEntity>)queryable;
// fails
}
return
sequence;
}
But i am not able to cast it to IQueryable again in order to apply further filters and paging. The returned object is of type "Kendo.Mvc.Infrastructure.AggregateFunctionsGroup" and thats why I keep getting an invalidcastexception.
"System.Data.Entity.Infrastructure.DbQuery`1[Kendo.Mvc.Infrastructure.AggregateFunctionsGroup]" cannot be converted to type "System.Linq.IQueryable`1[MyEntity]"
The internal query is looking as expected. Is there a way to cast it or what i am doing wrong? If not, how do you have to use this extension method in this custom binding scenario that must return a PagedListResult?
Many thanks in advcance,
Holger