Server paging

6 posts, 0 answers
  1. Marc
    Marc avatar
    67 posts
    Member since:
    Jul 2010

    Posted 04 Oct Link to this post

    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?

     

  2. Marc
    Marc avatar
    67 posts
    Member since:
    Jul 2010

    Posted 05 Oct in reply to Marc Link to this post

    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.

  3. Kendo UI is VS 2017 Ready
  4. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 06 Oct Link to this post

    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.
     
  5. Marc
    Marc avatar
    67 posts
    Member since:
    Jul 2010

    Posted 10 Oct in reply to Rosen Link to this post

    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?
  6. Marc
    Marc avatar
    67 posts
    Member since:
    Jul 2010

    Posted 10 Oct in reply to Marc Link to this post

    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?

     

  7. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 11 Oct Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready