public void WroteInstanceKeyMetadataValue(Guid key, XName name, InstanceValue value)
        {
            if (key == Guid.Empty)
            {
                throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
            }
            if (name == null)
            {
                throw Fx.Exception.ArgumentNull("name");
            }
            if (value == null)
            {
                throw Fx.Exception.ArgumentNull("value");
            }
            ThrowIfNotLocked();
            ThrowIfCompleted();
            ThrowIfNotTransactional("WroteInstanceKeyMetadataValue");

            InstanceKeyView keyView;
            if (!InstanceView.InstanceKeys.TryGetValue(key, out keyView))
            {
                if (InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
                }

                if (!value.IsWriteOnly() && !value.IsDeletedValue)
                {
                    Dictionary<Guid, InstanceKeyView> copy = new Dictionary<Guid, InstanceKeyView>(InstanceView.InstanceKeys);
                    keyView = new InstanceKeyView(key);
                    keyView.AccumulatedMetadataWrites.Add(name, value);
                    keyView.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
                    copy[keyView.InstanceKey] = keyView;
                    InstanceView.InstanceKeys = new ReadOnlyDictionaryInternal<Guid, InstanceKeyView>(copy);
                    InstanceView.InstanceKeysConsistency |= InstanceValueConsistency.Partial;
                }
            }
            else
            {
                keyView.AccumulatedMetadataWrites.Add(name, value);
            }
        }
 public void WroteInstanceKeyMetadataValue(Guid key, XName name, InstanceValue value)
 {
     InstanceKeyView view;
     if (key == Guid.Empty)
     {
         throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
     }
     if (name == null)
     {
         throw Fx.Exception.ArgumentNull("name");
     }
     if (value == null)
     {
         throw Fx.Exception.ArgumentNull("value");
     }
     this.ThrowIfNotLocked();
     this.ThrowIfCompleted();
     this.ThrowIfNotTransactional("WroteInstanceKeyMetadataValue");
     if (!this.InstanceView.InstanceKeys.TryGetValue(key, out view))
     {
         if (this.InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
         }
         if (!value.IsWriteOnly() && !value.IsDeletedValue)
         {
             Dictionary<Guid, InstanceKeyView> dictionary = new Dictionary<Guid, InstanceKeyView>(this.InstanceView.InstanceKeys);
             view = new InstanceKeyView(key);
             view.AccumulatedMetadataWrites.Add(name, value);
             view.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
             dictionary[view.InstanceKey] = view;
             this.InstanceView.InstanceKeys = new ReadOnlyDictionary<Guid, InstanceKeyView>(dictionary, false);
             System.Runtime.DurableInstancing.InstanceView instanceView = this.InstanceView;
             instanceView.InstanceKeysConsistency |= InstanceValueConsistency.Partial;
         }
     }
     else
     {
         view.AccumulatedMetadataWrites.Add(name, value);
     }
 }