Print Page | Close Window

Navigation Properties slowing down query

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2740
Printed Date: 04-May-2025 at 7:21pm


Topic: Navigation Properties slowing down query
Posted By: gregweb
Subject: Navigation Properties slowing down query
Date 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



Replies:
Posted By: pompomJuice
Date 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




Print Page | Close Window