使用HashTable属性序列化对象并存储在CouchBase

时间:2016-07-05 18:33:45

标签: c# couchbase

我们的团队已选择Couchbase作为我们应用程序的缓存。我们在此缓存中存储的对象是这样的对象

public class CatalogEntity
{
    public int Id { get; set; }
    public string Name { get; set; }

    // this property gives us trouble
    public Hashtable Attributes { get; set;}
}

在我们的代码中,从CouchBase缓存中检索对象后,我发现主要类型(IdName)的属性已正确反序列化,但Attributes的{​​{1}} 1}}类型未反序列化并保持为JSON。例如,如果我有类似

的东西
Hashtable

来自缓存的对象将具有var entity = new CatalogEntity(); entity.Attributes["foo"] = new Foo(); 属性作为Attributes["foo"]类的JSON表示。

我想知道如何正确序列化/反序列化Foo类型?我应该将对象序列化为二进制,而是将二进制流存储在CouchBase中吗?

1 个答案:

答案 0 :(得分:0)

您是否需要使用Hashtable?例如,您可以使用Dictionary<string,string>吗?

我认为你所看到的原因是Json.NET最好的序列化哈希表的尝试(参见StackOverflow上的这个问题:Serialize hashtable using Json.Net)。