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

Entity Framework no COUNT(*) and Top

5 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Terry Burns-Dyson
Top achievements
Rank 1
Terry Burns-Dyson asked on 13 May 2011, 03:27 PM
I was previously using LinqToSql with the telerik grids and even though I was mapping the data out to view objects, the grid was working nicely in that it was selecting count(*) and then selecting top x records from that set.

Now, we've switched our software to use Entity Framework with Automapper doing those mappings. The grid is no longer requesting the top x results from the query and this is causing an 1100 item recordset to take almost 4 seconds to show. The actual query is taking 3.6 seconds of that because of all the join data I'm pulling through for the model. Is there something I'm missing preventing the grid from paging the data?

5 Answers, 1 is accepted

Sort by
0
Terry Burns-Dyson
Top achievements
Rank 1
answered on 02 Jun 2011, 09:06 PM
Any ideas on this?

I've run the software through EFProfiler, and even though I see that the enumeration isn't happening until the screen is being rendered, there's no Skip(x).Take(x) occurring. I'm getting 1400 items back and the grid is only displaying 10. 

I have to map the objects coming out of the database, so I don't know what is going wrong.
0
Accepted
Atanas Korchev
Telerik team
answered on 03 Jun 2011, 07:31 AM
Hello Terry Burns-Dyson,

 The grid will uses the IQueryable extension methods to page the data. If you however pass it an IList or force execution of the IQueryable by calling Count() or ToList() or ToArray() - the grid  won't hit the database at all after that. Without seeing your code we cannot be sure what is really happening.

 You can try calling Take() and Skip() manually and see what happens with the profiler.

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Terry Burns-Dyson
Top achievements
Rank 1
answered on 03 Jun 2011, 02:40 PM
I was not returning them as IQueryable, with a lot of changes, I can get get it to SELECT COUNT(*) and SELECT TOP x, which is amazingly fast! But I now have another issue from this.

I read a recommendation by telerik on not returning entities right up to the screens, because the moment you use the Ajax select, you get a circular reference in the serialization. The recommendation was to map the objects. So, how do I map, yet still allow IQueryable from Entity Framework? 

If I use automapper, I get an error about not being able to convert Map to a store expression. If I hand code the objects, I'm ok, however if my database stores a integer and I want a timespan on the view, I can't do this because I can't use a new TimeSpan in the select clause of the EF. 
0
Atanas Korchev
Telerik team
answered on 04 Jun 2011, 08:54 AM
Hello Terry Burns-Dyson,

I am afraid your only option is to implement custom binding. Manual mapping will work as long as you don't add additional properties.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Terry Burns-Dyson
Top achievements
Rank 1
answered on 14 Jun 2011, 05:47 AM
We chose to manually map out the objects we want to display. Custom Binding looked a little too involved and we've got short timescales in which to do some of this stuff. The performance, once we got the IQueryable up to the front end was extremely fast!

I thought I should update this post in order that someone else should read it with the same question. 
Tags
Grid
Asked by
Terry Burns-Dyson
Top achievements
Rank 1
Answers by
Terry Burns-Dyson
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or