I'm having a problem with paging where the whole data set is return each turn rather than just the records that are due to appear on that page of the grid.
If I connect straight to the model e.g.
var model = new Context();
var reqassess = model.ReqAssesses;
return reqassess;
Then the query will select the top 30 records etc
But in our projects we tend to have a service layer and repositories
Controller:
public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(GetRequests().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
var reqassess = reqAssessService.GetReqAssess();
return reqassess;
Service layer:
public IEnumerable<ReqAssess> GetReqAssess()
{
return _repository.GetReqAssess();
}
Repository
public IEnumerable<ReqAssess> GetReqAssess()
{
return _context.ReqAssesses.Where(r => r.CompId == "TEST").ToList();
}
When I do it this way it returns the whole dataset everytime, which causes significant performance problems. Are you able to help me with this at all?
Thanks
6 Answers, 1 is accepted
This may happen if you forgot to include kendo.aspnetmvc.min.js to your project. The latter is vital for sending the right paging info to the controller.
Regards,Atanas Korchev
the Telerik team
Thanks for your reply.
I have these js files being loaded and in this order:
<script src="~/Scripts/jquery.min.js" type="text/javascript"></script>
<script src="~/Scripts/kendo.web.min.js" type="text/javascript"></script>
<script src="~/Scripts/kendo.aspnetmvc.min.js"></script>
And if I change the data retrieval techinque just to grab the data straight from the model in the controller then it works just as it should. So I think i'm ok in terms of the javascript files included. Do yooiu have any other ideas?
Thanks for your help.
Ben
Unfortunately we are out of more ideas. Could you show us how your grid configuration looks like? Ideally you could send us a running subset of your project which we can troubleshoot.
Regards,Atanas Korchev
the Telerik team
I've connected my files up to an SQL CE instance, i assuming i'm still getting the same problem but as I can't profile the queries in SQL CE i can't be certain but if I switch the connection string back to my sql server then I can see that the grid is requesting all rows from the table with each page (which is 600,000 odd rows).
I've attached a copy of my files, I really appreciate all your help with this as it seems like a great tool but i need to prove this part works before i can get authorisation to purchase it.
Thanks
Ben
The ToDataSourceResult extension method would perform paging in the database only if you use an IQueryable returned by a linq-enabled provider (Entity Framework, Linq to SQL etc). Your code returns all data even before giving it to the grid. This is what the ToList() method does - it executes the query and retrieves all items. Try returning an IQueryable instead:
public IQueryable<ReqAssess> GetReqAssess()
{
return _context.ReqAssesses.Where(r => r.CompId == "TEST");
}
public IEnumerable<ReqAssess> GetReqAssess(int take, int skip)
{
return _context.ReqAssesses.Where(r => r.CompId == "TEST").Skip(skip).Take(take).ToList();
}
All the best,
Atanas Korchev
the Telerik team
Thanks