This is a migrated thread and some comments may be shown as answers.

Server paging

5 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 04 Oct 2016, 08:22 PM

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

Sort by
0
Marc
Top achievements
Rank 1
answered on 05 Oct 2016, 02:57 PM

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.

0
Rosen
Telerik team
answered on 06 Oct 2016, 08:17 AM

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
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Marc
Top achievements
Rank 1
answered on 10 Oct 2016, 03:30 PM
Thanks for replying. There is never a ToList() called or anything that -should- materialize the query. However there is a conversion of the entity models to viewmodels prior to the ToDataSourceResult method call. Should we be calling ToDataSourceResult prior to any model conversion or invoking business logic on the models?
0
Marc
Top achievements
Rank 1
answered on 10 Oct 2016, 04:06 PM

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?

 

0
Rosen
Telerik team
answered on 11 Oct 2016, 06:57 AM

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.

Regards,
Rosen
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or