这可能是一个愚蠢的问题,但我无法保存在 sqlite 中。我已成功使用 XF 的 facebook 登录,但也想将那里的信息保存在 sqlite-net-pcl 中。两种型号是:
public class FacebookProfile
{
public string Name { get; set; }
public string Locale { get; set; }
public string Link { get; set; }
[OneToOne]
[JsonProperty("age_range")]
public AgeRange AgeRange { get; set; }
[JsonProperty("first_name")]
public string FirstName { get; set; }
[JsonProperty("last_name")]
public string LastName { get; set; }
public string Gender { get; set; }
public bool IsVerified { get; set; }
[PrimaryKey]
public int Id { get; set; }
}
public class AgeRange
{
public int Min { get; set; }
}
我已成功将信息下载到我的 FacebookProfile 模型并可以显示它。但是,当我尝试将它保存在我的 sqlite 数据库中时,FacebookProfile 的 AgeRange 属性在数据库中保存为 null 并且它应该具有一定的值。使用 sqlite 连接保存的代码是:
using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
{
conn.CreateTable<FacebookProfile>();
conn.Insert(fp); //fp is the FacebookProfile model info gotten from Facebook API and until this point, fp has agerange min value
}
此后,插入数据库的年龄范围保存为空,我不知道为什么或者我可能做错了什么。因此,当我尝试在视图模型中使用以下代码检索它时:
using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
{
conn.CreateTable<FacebookProfile>();
FacebookProfile = conn.Table<FacebookProfile>().FirstOrDefault();
}
从数据库中检索到的 FacebookProfile 的年龄范围值为 null,但其他我可以获得正确的信息。可能是什么问题?请帮忙!