我在 Xamarin 的项目中使用 Kinvey db。我熟悉解析指针功能。我想用 Kinvey 做同样的功能。Kinvey 也有参考功能。我试过了,但它总是将空值存储在 kinky db 中。所以我真的坚持这一点。这是我在 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; }
}
将数据存储在数据库中的代码是
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);
如果需要更多详细信息,请告诉我。