lI use a code looking like this one to select a large list of objects, for read only purpose :
using (DBContext db = new MyContextClass())
{
... data creation ...
db.SaveChanges();
}
using (DBContext db = new MyContextClass())
{
db.Configuration.LazyLoadingEnabled = false;
db.Configuration.ProxyCreationEnabled = false;
db.Configuration.AutoDetectChangesEnabled = false;
DbQuery data = db.Set(someType)
foreach (string propertyName op in somePropertieNames)
data = data.Include(propertyName);
foreach (object item in data.AsNoTracking())
ScanNavigatorsOf(item);
}
in ScanNavigatorsOf()
, I read all the navigation properties, and I noticed that the first object yielded by the foreach
loop has incomplete collections and references. It seems that the population of the navigation properties is not finished at the time the program hits my ScanNavigatorsOf(...)
method. All the other objects have complete navigation properties. I am running unit tests on this, so I can ensure that objects are well stored in the database.
How can I wait that the navigation collections and references of the loaded objects are fully populated?
Like explained in ObjectContext.ObjectMaterialized Event, the collections seems not materialized at the same time as the main object, but How can I know when the process is done?