New Posts New Posts RSS Feed: Include() behavior
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Include() behavior

 Post Reply Post Reply
Author
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Topic: Include() behavior
    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

 

Back to Top
gkneo View Drop Down
Newbie
Newbie
Avatar

Joined: 23-Jun-2010
Posts: 21
Post Options Post Options   Quote gkneo Quote  Post ReplyReply Direct Link To This Post 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.
 


Edited by gkneo - 10-Jan-2011 at 9:20am
Back to Top
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2011 at 8:59am

That works well - Thanks much!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down