简体   繁体   English

TextBlob为空

[英]TextBlob is null

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. 我是第一次使用SQLite,正在从事一个学生项目,并且做了很多研究,但无法解决问题。 I am trying to use sqlite-net-extensions, but my TextBlob is always null. 我正在尝试使用sqlite-net-extensions,但我的TextBlob始终为null。 How can use the methods with WithChilder, I cannot get them to work either 如何将方法与WithChilder一起使用,我也无法使它们工作

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 the SQLiteExtensions . 您还需要使用SQLiteExtensions的函数InsertWithChildren

Change the function SaveFoodNutrientAsync like this: 如下更改功能SaveFoodNutrientAsync

public Task<int> SaveFoodNutrientAsync(FoodNutrient foodNutrient)
{
    return database.InsertWithChildrenAsync(foodNutrient);
}

This will update the TextBlob to the value it corresponds. 这会将TextBlob更新为它对应的值。 You will also need to use the GetAllWithChildren to get your object with the blob. 您还需要使用GetAllWithChildren来获取带有对象的对象。

public Task<List<FoodNutrient>> GetFoodNutrientsAsync()
{
    return database.GetAllWithChildren<FoodNutrient>();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM