I’m attempting to perform partial updates with CouchbaseNetClient, but receive an InvalidCastException if I don’t use dynamic as the generic type.
I’m using a simple class like this:
public class TestClass
{
public string foo { get; set; }
public string bar { get; set; }
}
I’m able to make a partial update with this:
var builder = bucket.MutateIn< dynamic>(key).Replace(“foo”, “baz”);
var result = builder.Execute();
However, this generates an exception:
var builder = bucket.MutateIn< TestClass>(key).Replace(“foo”, “baz”);
var result = builder.Execute();
The exception occurs on this line within OptimizeSingleMutation of CouchbaseBucket because spec.Value contains the string “baz”, which cannot be cast to TestClass:
return new SubDocReplace< T>(builder, builder.Key, (T)spec.Value, null, _transcoder, _operationLifespanTimeout);
Is this use of MutateIn supported? Is there another way to perform partial updates without using dynamic? One issue with dynamic is that you are not able to use the lambda based extension method to perform updates.
This code results in a compile time exception: “An expression tree may not contain a dynamic operation”:
var builder = bucket.MutateIn< dynamic>(key).Replace(x => x.bar, “baz”);
var result = builder.Execute();
Should I be doing something different to make this work?
Thanks,
Glen