Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TextBlob为空_C#_Xamarin_Sqlite Net Extensions - Fatal编程技术网

C# TextBlob为空

C# TextBlob为空,c#,xamarin,sqlite-net-extensions,C#,Xamarin,Sqlite Net Extensions,我第一次与SQLite合作,我在做一个学生项目,我做了很多研究,但我无法解决我的问题。我试图使用sqlite网络扩展,但我的TextBlob总是空的。如何使用WithChilder的方法,我也无法让它们工作 这是我的模型课: public class FoodNutrient { [PrimaryKey, AutoIncrement] public int ID { get; set; } public string foodname { get; set; }

我第一次与SQLite合作,我在做一个学生项目,我做了很多研究,但我无法解决我的问题。我试图使用sqlite网络扩展,但我的TextBlob总是空的。如何使用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; }
}
公共类FoodNutrient
{
[主密钥,自动增量]
公共int ID{get;set;}
公共字符串foodname{get;set;}
公共字符串sd{get;set;}
公共字符串时间{get;set;}
[TextBlob(名称(nutrientsBlobbed))]
公共列表{get;set;}
公共字符串nutrientsBlobbed{get;set;}
}
公共类营养品
{
公共字符串名称{get;set;}
公共字符串组{get;set;}
公共字符串单元{get;set;}
公共双值{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>();
    }

}
公共类FoodDatabase
{
只读SQLiteAsyncConnection数据库;
公共FoodDatabase(字符串dbPath)
{
数据库=新的SQLiteAsyncConnection(dbPath);
database.CreateTableAsync().Wait();
}
公共任务SaveFoodNutrientAsync(FoodNutrient FoodNutrient)
{
返回数据库.InsertAsync(foodNutrient);
}
公共任务GetFoodNutrientsAsync()
{
返回database.Table().ToListAsync();
//返回database.GetAllWithChildren();
}
}

您还需要使用
SQLiteExtensions
的函数
InsertWithChildren

将函数
SaveFoodNutrientAsync
更改如下:

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