[英]TextBlob is null
我是第一次使用SQLite,正在從事一個學生項目,並且做了很多研究,但無法解決問題。 我正在嘗試使用sqlite-net-extensions,但我的TextBlob始終為null。 如何將方法與WithChilder一起使用,我也無法使它們工作
這是我的模型課:
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; }
}
這是我的數據庫:
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>();
}
}
您還需要使用SQLiteExtensions
的函數InsertWithChildren
。
如下更改功能SaveFoodNutrientAsync
:
public Task<int> SaveFoodNutrientAsync(FoodNutrient foodNutrient)
{
return database.InsertWithChildrenAsync(foodNutrient);
}
這會將TextBlob更新為它對應的值。 您還需要使用GetAllWithChildren
來獲取帶有對象的對象。
public Task<List<FoodNutrient>> GetFoodNutrientsAsync()
{
return database.GetAllWithChildren<FoodNutrient>();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.