private void AddModifyEntryCommands(ITransaction transaction, StateEntry stateEntry) { var compositePrimaryKeyValues = string.Join( PropertyValueSeparator, stateEntry.EntityType.GetKey().Properties.Select(p => EncodeKeyValue(stateEntry, p))); var redisPrimaryKeyIndexKeyName = string.Format(CultureInfo.InvariantCulture, PrimaryKeyIndexNameFormat, stateEntry.EntityType.Name); var redisDataKeyName = string.Format(CultureInfo.InvariantCulture, DataHashNameFormat, stateEntry.EntityType.Name, compositePrimaryKeyValues); transaction.AddCondition(Condition.KeyExists(redisPrimaryKeyIndexKeyName)); // first delete all the hash entries which have changed to null var changingToNullEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] == null) .Select(p => (RedisValue)p.Name).ToArray(); transaction.HashDeleteAsync(redisDataKeyName, changingToNullEntries); // now update all the other entries var updatedEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] != null) .Select(p => new HashEntry(p.Name, EncodeAsBytes(stateEntry[p]))).ToArray(); transaction.HashSetAsync(redisDataKeyName, updatedEntries); }
private void AddModifyEntryCommands(ITransaction transaction, StateEntry stateEntry) { var compositePrimaryKeyValues = ConstructKeyValue(stateEntry, (se, prop) => stateEntry.OriginalValues[prop]); var redisPrimaryKeyIndexKeyName = ConstructRedisPrimaryKeyIndexKeyName(stateEntry.EntityType); var redisDataKeyName = ConstructRedisDataKeyName(stateEntry.EntityType, compositePrimaryKeyValues); transaction.AddCondition(Condition.KeyExists(redisPrimaryKeyIndexKeyName)); // first delete all the hash entries which have changed to null var changingToNullEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] == null) .Select(p => (RedisValue)p.Name).ToArray(); transaction.HashDeleteAsync(redisDataKeyName, changingToNullEntries); // now update all the other entries var updatedEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] != null) .Select(p => new HashEntry(p.Name, EncodeAsBytes(stateEntry[p]))).ToArray(); transaction.HashSetAsync(redisDataKeyName, updatedEntries); }