This might be a silly question but I am having trouble saving in sqlite. I have used facebook login from XF successfully, but also want to save the info from there in sqlite-net-pcl. Two models are:
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; }
}
I have successfully downloaded the info to my FacebookProfile model and can display it. But, when I am trying to save it in my sqlite database, AgeRange property of FacebookProfile saves as null in the database and it should have a certain value. The code for saving using sqlite connection is:
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
}
After this point the agerange inserted in database is saved as null, I dont know why or I might be doing something wrong. So, when I try to retrieve this using following code in the viewmodel:
using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
{
conn.CreateTable<FacebookProfile>();
FacebookProfile = conn.Table<FacebookProfile>().FirstOrDefault();
}
The FacebookProfile retrieved from database has agerange value null but others I can get correct information. What might be the problem? Please help!