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