ToDataSourceResult Extension not populating DataSourceResult object

别说谁变了你拦得住时间么 提交于 2019-12-07 05:13:44

问题


The extension method that KendoUI adds (ToDataSourceResult), seems to fail on Pages > Page #1. It works fine the first time the page loads, but then when I try to use it with virtual scrolling, to fetch pages, 2,3,4 ... N asynchronously, the method ignores all the data in the IEnumerable object I am trying to transform.

My code is as follows:

I have a MVC controller that fetches data like so:

Database database = Database.GenerateDatabase();
ResultSet queryResults = database.GetEvents( 
    FilterHelper.GenerateQueryCriteria((List<IFilterDescriptor>) request.Filters, request.Page, request.PageSize) 
);

Database.GetEvents returns an object like so:

public class ResultSet {

    public List<ResultSetRow> Set;
    public int PageRowCount;
    public int TotalRecordCount;
}

Each ResultSetRow, is an instance of a class that has 1 string, and 2 ints as properties.

At this point, I set a break point and inspect the contents of ResultSet.Set. The database is properly populating the List with as many records as I specified with request.PageSize. I have confirmed that results are being returned for any and all page numbers.

The next stage, everything goes badly:

DataSourceResult result = ((IEnumerable<ResultSetRow>) queryResults.Set).ToDataSourceResult(request);

I inspect the contents of the DataSourceResult object, and its array property 'Data' is empty.

Why is my model (ResultSetRow), failing to convert to Kendo's DataSourceResult object?

Some additional info:

  • Aggregates, groups, sorts, and filters are not being used.
  • The number of results returned by Database.GetEvents matches the size of the page requested.

Thanks for your help SO community


回答1:


The main reason for using ToDataSourceResult() is that it runs filtering / ordering / grouping / paging on the database server. As such, it works best when given an IQueryable that hasn't yet been executed.

It does work on an IEnumerable, but then you have to load the entire table into memory, which is not scalable.

Because you only get one page's worth of data, when ToDataSourceResult is called, it thinks that is all the data in the database, and so returns an empty list for pages other than the first.



来源:https://stackoverflow.com/questions/14295924/todatasourceresult-extension-not-populating-datasourceresult-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!