Couchbase Lite 文档缺少属性

Couchbase Lite Doc missing properties

我一直在跨平台 (Xamarin) 应用程序项目中使用 Couchbase Lite 作为本地数据存储。我一直在从 Amazon Web 服务后端检索对象,使用 Newtonsoft JSON 序列化。自几周前我提出的 问题的答案以来,我的对象中的所有内容都正确序列化。但是,将我的食谱的 "group" 属性添加到 couchbase lite 中的文档中是不成功的。保存文档时不会抛出异常,但是当从数据库中检索文档时 "IngredientsWithHeaders" 和 "InstructionsWithHeaders" 都 return null。以下是save/retrieval代码:

public void SaveRecipe (Recipe recipe)
    {
        var document = db.GetDocument (recipe.RecipeId);
        var properties = new Dictionary<string, object> (){
            { "UserId",recipe.UserId },
            { "Title",recipe.Title },
            { "IngredientsList",recipe.IngredientsList },
            { "Notes",recipe.Notes },
            { "Tags",recipe.Tags },
            { "Yield",recipe.Yield },
            { "IngredientsWithHeaders",recipe.IngredientsWithHeaders },
            { "InstructionsWithHeaders",recipe.InstructionsWithHeaders }
        };
        var rev = document.PutProperties(properties);
        Debug.Assert (rev != null, "Revision is null");
        var newRev = document.CurrentRevision.CreateRevision ();
        newRev.SetAttachment ("image.jpg", "image/jpeg", recipe.Image);
        newRev.Save ();
    }

public IEnumerable<Recipe> GetRecipes ()
    {
        var query = db.CreateAllDocumentsQuery ();
        query.AllDocsMode = AllDocsMode.AllDocs;
        var rows = query.Run ();
        Debug.WriteLine ("Recipes in Query: "+rows.Count);
        return rows.Select (recipe => ToRecipe (recipe.Document));
    }

private Recipe ToRecipe(Document doc){
        Recipe recipe = new Recipe(doc.Id);
        recipe.UserId = doc.GetProperty<string> ("UserId");
        recipe.Title = doc.GetProperty<string> ("Title");
        recipe.IngredientsList = doc.GetProperty<List<string>> ("IngredientsList");
        recipe.Notes = doc.GetProperty<List<string>> ("Notes");
        recipe.Tags = doc.GetProperty<ISet<string>> ("Tags");
        recipe.Yield = doc.GetProperty<int> ("Yield");
        recipe.IngredientsWithHeaders = doc.GetProperty<List<Group<string,IngredientJson>>> ("IngredientsWithHeaders");
        recipe.InstructionsWithHeaders = doc.GetProperty<List<Group<string,string>>> ("InstructionsWithHeaders");
        var rev = doc.CurrentRevision;
        var image = rev.GetAttachment ("image.jpg");
        if (image != null) {
            Debug.WriteLine ("There is an image here");
            recipe.Image = image.Content.ToArray();
        }
        return recipe;
    }

ToRecipe() 方法更改为以下解决了问题:

private Recipe ToRecipe(Document doc){
    Recipe recipe = new Recipe(doc.Id);
    recipe.UserId = doc.GetProperty<string> ("UserId");
    recipe.Title = doc.GetProperty<string> ("Title");
    recipe.IngredientsList = doc.GetProperty<List<string>> ("IngredientsList");
    recipe.Notes = doc.GetProperty<List<string>> ("Notes");
    recipe.Tags = doc.GetProperty<ISet<string>> ("Tags");
    recipe.Yield = doc.GetProperty<int> ("Yield");
    recipe.IngredientsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, IngredientJson>>>(doc.GetProperty ("IngredientsWithHeaders").ToString());

    recipe.InstructionsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, string>>>(doc.GetProperty("InstructionsWithHeaders").ToString());

    var rev = doc.CurrentRevision;
    var image = rev.GetAttachment ("image.jpg");
    if (image != null) {
        Debug.WriteLine ("There is an image here");
        recipe.Image = image.Content.ToArray();
    }
    return recipe;
}