I'm not sure what you are trying to achieve. At least not with Delta<TEntity>.Patch(..)
Assuming you have a Product entity and somewhere in your PATCH action you have
[AcceptVerbs("PATCH")] public void Patch(int productId, Delta<Product> product) { var productFromDb =
When a Product is created, inside it calls the Delta<TEntityType> constructor, which looks like this (a parameterless constructor also calls this, passing typeof(TEntityType)
public Delta(Type entityType) { this.Initialize(entityType); }
Initialize method is as follows
private void Initialize(Type entityType) { // some argument validation, emitted for the sake of brevity this._entity = (Activator.CreateInstance(entityType) as TEntityType); this._changedProperties = new HashSet<string>(); this._entityType = entityType; this._propertiesThatExist = this.InitializePropertiesThatExist(); }
The interesting part here is this._propertiesThatExist , which is a Dictionary<string, PropertyAccessor<TEntityType>> , which contains properties of the product type. PropertyAccessor<TEntityType> is an internal type that simplifies property management.
When you call product.Patch(productFromDb) , this is what happens under the hood
// some argument checks PropertyAccessor<TEntityType>[] array = ( from s in this.GetChangedPropertyNames() select this._propertiesThatExist[s]).ToArray<PropertyAccessor<TEntityType>>(); PropertyAccessor<TEntityType>[] array2 = array; for (int i = 0; i < array2.Length; i++) { PropertyAccessor<TEntityType> propertyAccessor = array2[i]; propertyAccessor.Copy(this._entity, original); }
As you can see, it gets the changed properties, iterates over them and sets the values โโfrom the instance passed to the Patch action to the instance you get from db. So the operation you pass in, the property name and the value to add do not reflect anything.
propertyAccessor.Copy(this._entity, original) method body
public void Copy(TEntityType from, TEntityType to) { if (from == null) { throw Error.ArgumentNull("from"); } if (to == null) { throw Error.ArgumentNull("to"); } this.SetValue(to, this.GetValue(from)); }