Print Page | Close Window

Include() behavior

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=2430
Printed Date: 13-Mar-2025 at 4:30am


Topic: Include() behavior
Posted By: chuckc
Subject: Include() behavior
Date Posted: 09-Jan-2011 at 9:41am

I've run across an unexpected behavior when using Include().  It appears that appending an Include to the query after initial declaration is not effective.

The code below illustrates what I'm seeing.  Notice where the Include is used and the resulting time required to run the navigation property access test loop.


                    IEntityQuery<Certificate> q =

                        new EntityQuery<Certificate>().Where(c => c.IsActive == true &&

                                            c.PolicyPeriod.ExpirationDate > System.DateTime.Now &&

                                            (c.Provider.SpecialtyId == pediatricianSpecialityId ||

                                             c.Provider.SpecialtyId == emergencyMedicineSpecialityId))

                                            .Include("Provider.Person");

                     _certificates = iCatalystEntityManager.DefaultManager.ExecuteQuery(q).ToList();

                     string n;

                    DateTime start = DateTime.Now;

                    foreach (Certificate c in _certificates)

                    {

                        n = c.Provider.Person.DisplayName;

                    }

                    TimeSpan delta = DateTime.Now - start;

                    // delta = 0.014 seconds

 

  

 Changed code, rebuilt and re-run.

                    IEntityQuery<Certificate> q =

                        new EntityQuery<Certificate>().Where(c => c.IsActive == true &&

                                            c.PolicyPeriod.ExpirationDate > System.DateTime.Now &&

                                            (c.Provider.SpecialtyId == pediatricianSpecialityId ||

                                             c.Provider.SpecialtyId == emergencyMedicineSpecialityId));

                    q.Include("Provider.Person"); // << applying after initial query creation is ineffective

                     _certificates = iCatalystEntityManager.DefaultManager.ExecuteQuery(q).ToList();

                     string n;

                    DateTime start = DateTime.Now;

                    foreach (Certificate c in _certificates)

                    {

                        n = c.Provider.Person.DisplayName;

                    }

                    TimeSpan delta = DateTime.Now - start;

                    // delta = 19 seconds

Thanks

 




Replies:
Posted By: gkneo
Date Posted: 10-Jan-2011 at 9:17am
Hi, chuck


You should  rather use:

q = q.Include ("Provider.Person");

That way, q is a new IEntityQuery with the Where and Include statements you have specified.

The "delta" (19 seconds) is ok as it has to query the server for every iteration looking for "Provider" and "Person", because the Include statement was not effective.


Regards,


Guillermo.
 


Posted By: chuckc
Date Posted: 11-Jan-2011 at 8:59am

That works well - Thanks much!



Print Page | Close Window