2014-12-26 31 views
1

第三個斷言失敗。它是一個CouchbaseClient錯誤?CouchbaseClient.StoreJson不存儲Id屬性

private class StoreJsonTest 
    { 
     public int Id { get; set; } 
     public string StrProp { get; set; } 
     public int IntProp { get; set; } 
    } 

    [Test] 
    public void CouchBase() 
    { 
     var storeJsonTest = new StoreJsonTest() {Id = 1, StrProp = "Test str prop", IntProp = 10}; 
     string key ="testStoreJson"+ Guid.NewGuid().ToString(); 
     CouchbaseClient couchbaseClient = new CouchbaseClient(); 
     couchbaseClient.StoreJson(StoreMode.Add, key, storeJsonTest); 
     var extractedJson = couchbaseClient.GetJson<StoreJsonTest>(key); 
     Assert.That(extractedJson.StrProp == storeJsonTest.StrProp); 
     Assert.That(extractedJson.IntProp == storeJsonTest.IntProp); 
     Assert.That(extractedJson.Id == storeJsonTest.Id); 
    } 

如何將Id屬性存儲到couchbase?

回答

1

地方添加下面一行在你的應用程序的啓動:

CouchbaseClientExtensions.JsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); 

默認合同解析器是內部實現序列化除了ID屬性的一切。

'CamelCasePropertyNamesContractResolver'來自Newtonsoft.Json.Serialization命名空間。