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

MVC ToDataSourceResult - query called twice?

4 Answers 202 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 30 May 2014, 05:47 PM
Hello,

We have an MVC application using Entity Framework as the interface into our database.  We recently added some database logging to our application in order to do some performance analysis.  I noticed that in the Read methods for our Kendo grids our SQL seems to be executing twice.  Drilling into this a bit more, I found that the Kendo.MVC.Extensions ToDataSourceResult() method against an IQueryable was the place where the double execution was happening.  A few of our queries take a fair amount of time to execute, so having them run twice is a performance drag.  I was hoping to get some help determining why this might be happening.  My best guess is that this is due to paging needing to find out the total row count and then a second execution to get the actual data, but it's only a guess.  If your team could help out, I'd really appreciate it.  Thanks!

Regards,
Brian

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 03 Jun 2014, 02:10 PM
Hello Brian,

The assumption that you shared is correct, we cannot get the total number of records without using the Count() extension method LINQ provides. The only way to optimize or change this default behavior is to create your own CustomBinding where you can use a session variable that holds the number of records.

result.Total = data.Count();
result.Data = data.Execute(selector);


Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian Roth
Top achievements
Rank 1
answered on 03 Jun 2014, 07:43 PM
Hi Petur,

Thanks for the reply.  One further question - when you call the Count() method, do you do that on the IQueryable collection or do you convert it ToList first?

I really appreciate the help.  I'm going to look into the CustomBinding in the near future.  I think the hardest part for that would be implementing the filter logic.  Do you know if there are any plans to make public the filter methods that you are using in the ToDataSourceResult?

Regards,
Brian
0
Petur Subev
Telerik team
answered on 04 Jun 2014, 08:44 AM
Hello Brian,

It is over the IQueryable interface (we do not use ToList() it will be a performance hit), you can check the complete implementation in the Extensions/QueryableExtensions.cs ToDataSourceResult method of the Kendo.MVC project.

I am not aware of such plans, you can check how the filtering implementation goes in the same project.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian Roth
Top achievements
Rank 1
answered on 12 Jun 2014, 08:51 PM
Thanks!  I didn't realize the source code was available to look at.  That helps a lot.

Regards,
Brian
Tags
General Discussions
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Brian Roth
Top achievements
Rank 1
Share this question
or