I am attempting to have an ajax grid that does server side paging. (For reference, I am using Entity Framework for db context, and Automapper for model to view model mapping). The paging is working clientside, but it just pulls in all the data from my db then pages. I cannot seem to get the paging to reflect at the sql query level without doing it manually (which defeats the purpose of passing the request to the DataSourceResult(). Am i missing something, or must i do this manually?
As far as I can understand, you need to apply the paging within the SQL query. If that is the case, you will need to call the ToDataSourceResult(request) before mapping the db Model to the ViewModel:
var agencyContacts = dbContext.AgencyContacts.Include("Agency").OrderBy(a => a.AgencyCode);
var result = agencyContacts.ToDataSourceResult(request);
result.Data = result.Data.Cast<AgencyContact>().ProjectTo<AgencyContactViewModel>();return Json(result, JsonRequestBehavior.AllowGet);
Any logic executed after AutoMapping (ProjectTo<>) on the mapped collection will be executed on the server and not within the query itself.
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.