实际上我正在使用 SQLite 数据库开发 Windows Metro 应用程序。我使用 sqlite manager (mozilla) 进行管理。我尝试删除级联,但它仅在 sqlite 管理器中有效,不在 C# 代码中:
我的功能
public async Task<string> DeleteSurvey(int SurveyID)
{
string result = string.Empty;
var db = new SQLite.SQLiteAsyncConnection(App.DBPath);
var survey = await GetSurvey(SurveyID);
var res = await db.DeleteAsync(survey);
if (res > 0)
result = "Success";
else
result = "Echec";
return result;
}
db.CreateTable<Survey>();
SQLiteCommand command1 = new SQLiteCommand(db);
command1.CommandText = "create table if not exists SurveyItemGroup";
command1.CommandText += "(ID integer primary key autoincrement not null, IDSurvey integer,";
command1.CommandText += "Number integer, Name varchar(50), FOREIGN KEY(IDSurvey) REFERENCES Survey(ID) ON DELETE CASCADE ON UPDATE CASCADE)";
command1.ExecuteNonQuery();
在 C# 代码中,它只删除调查表而不是两者(调查和调查项目组)
PS:我对 pragma ( pragma foreign_keys=ON;
) 有同样的问题,它只有在我使用 sqlite manager 时才有效。