public override void Update <T>(IChangeTracker changeTracker, IEntityManager entityManager, T existing, T entity) { var innerElementType = GetCollectionElementType(); var updateValues = GetValue <IEnumerable>(entity) ?? new List <object>(); var dbCollection = GetValue <IEnumerable>(existing) ?? CreateMissingCollection(existing, innerElementType); var dbHash = dbCollection.Cast <object>().ToDictionary(item => entityManager.CreateEntityKey(item)); // Iterate through the elements from the updated graph and try to match them against the db graph var updateList = updateValues.OfType <object>().ToList(); for (int i = 0; i < updateList.Count; i++) { var updateItem = updateList[i]; var key = entityManager.CreateEntityKey(updateItem); // try to find item with same key in db collection object dbItem; if (dbHash.TryGetValue(key, out dbItem)) { UpdateElement(changeTracker, entityManager, existing, updateItem, dbItem); dbHash.Remove(key); } else { updateList[i] = AddElement(changeTracker, entityManager, existing, updateItem, dbCollection); } } // remove obsolete items foreach (var dbItem in dbHash.Values) { RemoveElement(changeTracker, dbItem, dbCollection); } }