New Posts New Posts RSS Feed: Navigation Properties slowing down query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Navigation Properties slowing down query

 Post Reply Post Reply
Author
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Topic: Navigation Properties slowing down query
    Posted: 02-Jun-2011 at 7:10am
I have this query:
 
var query = this.EmailEntityManager.EmailFolderEntities.Where(a => a.EmailAccountId == this.CurrentEmailAccount.Id).Where(a=> a.Visible == true).Where(a => a.IsDeleted ==false);
 
 
EmailFolderEntities has several navigation properties such as EmailAccount and ChildFolders.   When the query executes, these navigation properties are being populated.  The issue with that is that it slows down the query dramatically - like from a second or two to 10 seconds.  If I delete the navigation properties, then the query speeds up again.
 
I thought that the navigation properities would not be populated unless there was a specific "Include" statement in the query such as
 
var query = this.EmailEntityManager.EmailFolderEntities.Where(a => a.EmailAccountId == this.CurrentEmailAccount.Id).Where(a=> a.Visible == true).Where(a => a.IsDeleted ==false)
.include("EmailAccount");
 
 
Greg
Back to Top
pompomJuice View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Jul-2010
Location: ZA
Posts: 28
Post Options Post Options   Quote pompomJuice Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jun-2011 at 12:42am
Are you developing in WPF or SL?

Navigational properties in SL are loaded asynchronously (WPF might be sync?). Therefore, if you pump those query results into a DataGrid with auto generate fields set to true, it would definitely do async fetches on all those nav properties because the DataGrid is touching them. Whatever the case, something in your code is trying to view those nav properties!

If this is your scenario then you could speed the process up by Include(ing) the nav properties from the get go, saving you the time those individual async/sync fetches would have taken.

W



Edited by pompomJuice - 03-Jun-2011 at 12:44am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down