我正在尝试将数据存储在android设备上的本地SQLite数据库中,但是存储的对象数据为NULL。正在设置ID,但所有其他数据均为空。
我最初试图存储一个包含四个属性(int,string,string和一个列表)的对象。但是没有存储数据。我以为是列表,因为在数据库中存储数据时,每个对象都必须有自己的行?因此,我决定将列表分成几行,然后将它们存储在第二个表中,并使用外键联接。
{
bool confirmed = await DisplayAlert("Confirmation","Is this Recipe ready to be created?","Yes","No");
if (confirmed)
{
//get meat type from picker...
Enums.MeatType mt = (Enums.MeatType)Enum.Parse(typeof(Enums.MeatType),pkrRecipeType.SelectedItem.ToString());
//create recipe object with name,meat type...
Recipe r = new Recipe(entRecipeName.Text,mt);
SQLiteConnection conn = new SQLiteConnection(App.FilePath);
//need to add the recipe to the recipes database
using (conn)
{
//create the table if it doesnt exist...
conn.Createtable<Recipe>();
//insert the recipe into the table...
conn.Insert(r);
}
//need to add the ingredients of the recipe to the database
using (conn)
{
conn.Createtable<Ingredient>();
foreach (Ingredient i in listOfIngredients)
{
i.RecipeID = r.Id;
conn.Insert(i);
conn.Update(i);
}
}
await Navigation.PushAsync(new MainPage());
}
}
没有错误产生,当我尝试从表中检索数据时,只是空值。我目前有两个表格,食谱和成分。它们通过食谱ID绑定在一起,并且食谱数据可以很好地存储,但是配料却不能。
还希望使用Xamarin,TwinCoders的SQLiteNetExtensions添加即时通讯。