[英]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.