代码之家  ›  专栏  ›  技术社区  ›  P a u l

SQLite PRAGMA外键问题

  •  0
  • P a u l  · 技术社区  · 16 年前

    我修改了System.Data.SQLite以使用最新版本的 SQLite 自动强制外键而不使用自定义触发器的引擎。

    我也在使用 SubSonic ORM

    如何确保对每个SQLiteConnection.Open()调用语句“PRAGMA foreign_keys=true”?必须调用它,否则外键不起作用。

    2 回复  |  直到 16 年前
        1
  •  2
  •   P a u l    16 年前

    为了解决这个问题,我在SQLiteConnection类的ConnectionString中添加了一个“外键”属性。

    外键=关闭

        2
  •  1
  •   Raminder    16 年前

            string databasePath = "Your database path here";
            string connectionString = "Data Source=" + databasePath;
            connection = new SQLiteConnection(connectionString);
            connection.Open();
    
            const string sqlString = "PRAGMA foreign_keys = ON;";
            SQLiteCommand command = new SQLiteCommand(sqlString, connection);
            command.ExecuteNonQuery();
    
    推荐文章