3

実際、私は SQLite データベースを使用して Windows メトロ アプリを開発しています。管理にはsqliteマネージャー(mozilla)を使用しています。カスケードの削除を試みましたが、C#コードではなくsqliteマネージャーでのみ機能します:

私の機能


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# コードでは、Survey と SurveyItemGroup の両方ではなく、Survey テーブルのみを削除します。

PS: プラグマ ( pragma foreign_keys=ON;) にも同じ問題があります。

4

1 に答える 1

6

(OPがこれを彼の解決策として指摘したため、この回答を追加していますが、コメントのみです。)

現在、ON DELETE CASCADE が機能するには、新しい接続ごとpragma foreign_keys=on;に発行する必要があります。現在、永続的な設定ではありません。

于 2015-03-08T21:16:39.703 に答える