internal void RemapEntityKeys(KeyMapping keyMapping) { if (keyMapping.Map.Count == 0) { return; } using (Activate()) { if (!LazyKeyGenerationIsEnabled) { Persist(PersistReason.RemapEntityKeys); Invalidate(); } OrmLog.Debug(Strings.LogSessionXRemappingEntityKeys, this); foreach (var entityState in EntityChangeRegistry.GetItems(PersistenceState.New)) { var key = entityState.Key; var remappedKey = keyMapping.TryRemapKey(key); if (remappedKey != key) { entityState.RemapKey(remappedKey); } EntityStateCache.Add(entityState); } ProcessChangesOfEntitySets(entitySetState => entitySetState.RemapKeys(keyMapping)); EntityEvents.RemapKeys(keyMapping); } }
private async ValueTask RemapEntityKeys(KeyMapping keyMapping, bool isAsync, CancellationToken token = default) { if (keyMapping.Map.Count == 0) { return; } using (Activate()) { if (!LazyKeyGenerationIsEnabled) { await Persist(PersistReason.RemapEntityKeys, isAsync, token).ConfigureAwait(false); Invalidate(); } if (IsDebugEventLoggingEnabled) { OrmLog.Debug(Strings.LogSessionXRemappingEntityKeys, this); } foreach (var entityState in EntityChangeRegistry.GetItems(PersistenceState.New)) { var key = entityState.Key; var remappedKey = keyMapping.TryRemapKey(key); if (remappedKey != key) { entityState.RemapKey(remappedKey); } EntityStateCache.Add(entityState); } ProcessChangesOfEntitySets(entitySetState => entitySetState.RemapKeys(keyMapping)); EntityEvents.RemapKeys(keyMapping); } }
/// <summary> /// Remaps the event keys in accordance with specified <paramref name="keyMapping"/>. /// </summary> /// <param name="keyMapping">The key mapping.</param> public void RemapKeys(KeyMapping keyMapping) { if (subscribers == null || subscribers.Count == 0) { return; } var copy = new Dictionary <Triplet <Key, FieldInfo, object>, Delegate>(subscribers); subscribers.Clear(); foreach (var kvp in copy) { var triplet = kvp.Key; var subscriber = kvp.Value; if (subscriber == null) // Strange, but there is report is can be null: http://goo.gl/W6xo { continue; } var key = keyMapping.TryRemapKey(triplet.First); AddSubscriber(key, triplet.Second, triplet.Third, kvp.Value); } }