I'm using the MVC wrappers and entity framework and SQL server. Is server paging supported at the SQL level with the Kendo DataSourceRequest/ToDataSourceResult?
It seems like I always get a full table scan into memory from the database prior to any paging taking place (Iqueryable object). Do I need to write custom paging and sorting logic to limit results coming back from the database?
5 Answers, 1 is accepted
As an update to what I'm finding is that even if we pass IQueryable throughout the application layers, the linq to sql is never generated properly (ie paging is set to 100, but all the records are fetched). We are using a repository pattern where entites are queried, converted into application models in the service layer, then coverted into viewmodels.
If we need to parse out the kendo datasource object and create our own paging, filtering and sorting logic, then the usefulness of using Kendo is pretty diminished. Feel free to point me to a relevant documentation on this.
Hello Marc,
In order data processing such as paging/sorting/filtering etc. to be executed at the database level a non evaluated IQueryable<> should be provided. It should be a non evaluated one in order for ToDataSourceResult logic to be able to enhance the LINQ Expression tree of the query with the appropriate modifications before sending the request to the DB server. Therefore, judging by the provided information I suspect that the IQueryable you are passing in has been already "materialized" (you should verify that you are not calling ToList or iterating over it for example before it is pass to ToDataSourceResult extension method).
Regards,Rosen
Telerik by Progress
Considering the following lines of code in an MVC controller:
var customers = ToViewModels(_customerService.GetCustomers()); //queries all 50k records, then applies paging
return Json(customers .ToDataSourceResult(request));
vs.
var customers = _requestService.GetCustomers().ToDataSourceResult(request); //applies proper paging fetch size to query
var models = (IEnumerable<Customer>) result.Data;
var viewModels = ToViewModels(models);
return ????
What is the best approach here?
Hello Marc,
In order to apply the projection you could use the overload of the ToDataSourceResult extension method which expects a function as a parameter ->
public static DataSourceResult ToDataSourceResult<TModel, TResult>(this IEnumerable<TModel> enumerable, DataSourceRequest request, Func<TModel, TResult> selector)
If you are using the second approach you have pasted, you will need to construct a new DataSourceResult instance and assign the modified result and total.
return new DataSourceResult {
Data = viewModels,
Total = result.Total
}
However, you should be aware that in case of server grouping the shape of the result.Data is different thus you will need to adapt the ToViewModels method.
Rosen
Telerik by Progress