Description
I'm noticing some odd behavior when trying to do GetAsync<T> where T is a class I've specified. I would have expected that GetAsync<T> would have returned the document I've inserted, but it appears that it's returning the document within a document, with a field name of "".
Here's some sample code illustrating the issue, plus a workaround:
var connString = "couchbase://10.0.0.220"; |
var options = new ClusterOptions(); options.WithBucket("bugtest") .WithCredentials("Administrator", "danger") .WithServers(connString); |
var cluster = new Cluster(connString, options); |
var bucketResult = cluster.BucketAsync("bugtest"); |
bucketResult.Wait();
|
var collection = bucketResult.Result.DefaultCollection();
|
var testData = new TestData() { StringTest = "test", IntTest = Int32.MaxValue, DictTest = new Dictionary<string, int>(){ {"key1", 1}, {"key2", 2}, {"key3", 3} } }; |
var key = "test:mydoc"; |
collection.InsertAsync(key, testData);
|
var getResult = collection.GetAsync(key, options => { });
|
getResult.Wait();
|
var r = getResult.Result; var badResult = r.ContentAs<TestData>(); // this should return the object we inserted, but it does not /* |
It looks like it's returning a document that looks like this: |
{"" : {<the actual document content>}} |
*/
|
//this is the workaround for Get |
var correctResult = (JToken)(r.ContentAs<dynamic>()[""]); |
var cr = (TestData)correctResult.ToObject(typeof(TestData)); //this returns what I would have expected. |