如何在使用 Sqlite.net 的 Windows 8 应用商店应用中更新现有表的架构?但是,我尝试CreateTableAsync
创建一个新表,丢失现有数据。它应该在插入时更新架构;但是,当我尝试为不在表中的列插入数据时,它会崩溃,表明该列不存在。
问问题
965 次
1 回答
0
您需要使用.Update
而不是创建新表。将.Update
通过您提供的模型创建一个新数据库,并将现有数据复制/粘贴到新数据库中。
我用于检查和更新数据库的代码
if(result.FirstOrDefault().version != 3 || result.FirstOrDefault().version == 0)
{
//Update Database with new columns by the updated model called Unlockables
conn.CreateTable<Unlockables>();
try
{
var existingRow = (conn.Table<Unlockables>().Where(c => c.Id == 1)).SingleOrDefault();
existingRow.version = 3;
existingRow.SelectedTheme = 0;
existingRow.Theme1 = true;
int succes = conn.Update(existingRow);
}
catch(Exception ex)
{
Debug.WriteLine(ex);
}
}
希望这会有所帮助:)
于 2014-01-29T11:15:18.967 回答