private void PutLoadedStatesInCache(IEnumerable <Tuple> queryResult, RecordSetReader reader, HashSet <Key> foundedKeys) { var records = reader.Read(queryResult, Provider.Header, manager.Owner.Session); foreach (var record in records) { if (record != null) { var fetchedKey = record.GetKey(); var tuple = record.GetTuple(); if (tuple != null) { manager.SaveStrongReference(manager.Owner.UpdateState(fetchedKey, tuple)); foundedKeys.Add(fetchedKey); } } } }
public void UpdateCache() { if (itemsQueryTask == null) { return; } var areToNotifyAboutKeys = !manager.Owner.Session.Domain.Model .Types[referencingFieldDescriptor.Field.ItemType].IsLeaf; var reader = manager.Owner.Session.Domain.EntityDataReader; var records = reader.Read(itemsQueryTask.Result, QueryProvider.Header, manager.Owner.Session); var entityKeys = new List <Key>(itemsQueryTask.Result.Count); List <Pair <Key, Tuple> > auxEntities = null; var association = ReferencingField.Associations.Last(); if (association.AuxiliaryType != null) { auxEntities = new List <Pair <Key, Tuple> >(itemsQueryTask.Result.Count); } foreach (var record in records) { for (int i = 0; i < record.Count; i++) { var key = record.GetKey(i); if (key == null) { continue; } var tuple = record.GetTuple(i); if (tuple == null) { continue; } if (association.AuxiliaryType != null) { if (i == 0) { auxEntities.Add(new Pair <Key, Tuple>(key, tuple)); } else { manager.SaveStrongReference(manager.Owner.UpdateState(key, tuple)); entityKeys.Add(key); if (areToNotifyAboutKeys) { referencingFieldDescriptor.NotifySubscriber(ownerKey, key); } } } else { manager.SaveStrongReference(manager.Owner.UpdateState(key, tuple)); entityKeys.Add(key); if (areToNotifyAboutKeys) { referencingFieldDescriptor.NotifySubscriber(ownerKey, key); } } } } manager.Owner.UpdateState(ownerKey, ReferencingField, ItemCountLimit == null || entityKeys.Count < ItemCountLimit, entityKeys, auxEntities); }