I am working with SQLite for the first time, I have working on a student project, and I have done a lot of research, but I cannot fix my problem. I am trying to use sqlite-net-extensions, but my TextBlob is always null. How can use the methods with WithChilder, I cannot get them to work either
This is my model class:
public class FoodNutrient
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string foodname { get; set; }
public string sd { get; set; }
public string time { get; set; }
[TextBlob(nameof(nutrientsBlobbed))]
public List<NutrientItem> nutrients { get; set; }
public string nutrientsBlobbed { get; set; }
}
public class NutrientItem
{
public string name { get; set; }
public string group { get; set; }
public string unit { get; set; }
public double value { get; set; }
}
This is my database:
public class FoodDatabase
{
readonly SQLiteAsyncConnection database;
public FoodDatabase(string dbPath)
{
database = new SQLiteAsyncConnection(dbPath);
database.CreateTableAsync<FoodNutrient>().Wait();
}
public Task<int> SaveFoodNutrientAsync(FoodNutrient foodNutrient)
{
return database.InsertAsync(foodNutrient);
}
public Task<List<FoodNutrient>> GetFoodNutrientsAsync()
{
return database.Table<FoodNutrient>().ToListAsync();
//return database.GetAllWithChildren<FoodNutrient>();
}
}
You also need to use the function
InsertWithChildren
of theSQLiteExtensions
.Change the function
SaveFoodNutrientAsync
like this:This will update the TextBlob to the value it corresponds. You will also need to use the
GetAllWithChildren
to get your object with the blob.