4

Xamarin を使用したプロジェクトに Kinvey db を使用しています。私はパースポインタ機能に精通しています。Kinvey でも同じ機能を実現したいと考えています。Kinvey には参照機能もあります。私はそれを試しましたが、常にnull値をkinky dbに保存します。だから私は本当にこれにこだわっています。null値を格納するKinveyでの最終結果は次のとおりです

結果: {"type":"KinveyRef","_id":"55f18c9d39d29b9e0f023748","_collection":"Color","_obj":null}

私のデータベースモデルクラス

[JsonObject(MemberSerialization.OptIn)]
public class Gallery
{
    public Gallery ()
    {
    }

    [JsonProperty("_id")]
    public string ID { get; set; }

    [JsonProperty]
    public string Name { get; set; }

    [JsonProperty]
    public KinveyReference<Color> color;
}


[JsonObject(MemberSerialization.OptIn)]
public class Color
{ 
    public Color ()
    {
    }

    [JsonProperty("_id")]
    public string ID { get; set; }

    [JsonProperty]
    public string Title { get; set; }

    [JsonProperty]
    public string Code { get; set; }

}

データをdbに格納するコードは

 AsyncAppData<Gallery> entityCollection = Client.AppData<User>("Gallery", typeof(Gallery));
            entityCollection.setCache(cache, CachePolicy.CACHE_FIRST);

            AsyncAppData<Color> colorCollection = Client.AppData<Color>("Color", typeof(Color));
            colorCollection.setCache(lcache, CachePolicy.CACHE_FIRST);

            Color color = new Color();
            color.Title = "Pink";
            color.Code = "ff00ff";

            Color colorEnt  = await colorCollection.SaveAsync(color);

            Gallery gallery = new Gallery();
            gallery.Name = "HARSHAD";
            gallery.ID = "1211222as";
            KinveyReference<Color> reference = new KinveyReference<Color>("Color",colorEnt.ID); 
            gallery.color = reference;

            Gallery entity = await entityCollection.SaveAsync(gallery);

詳細が必要な場合はお知らせください。

4

0 に答える 0