我修改System.Data.SQLite使用最近的SQLite 引擎的版本自动强制执行外键,而无需使用自定义的触发器。

我还使用亚音速 2.x的,但这将适用

到任何 ORM 构架使用SQLite是'开后期接近初

你将如何保证声明“PRAGMA foreign_keys =真”,就是号召每SQLiteConnection.Open()?它被称为键和外键不起作用。

有帮助吗?

解决方案

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

外键= ON 外键= OFF

其他提示

您不需要修改System.Data.SQLite,如果你想使用最新版本的SQLite,只需使用System.Data.SQLite的ManagedOnly版本,然后只更新最新版本的sqlite3.dll。为了使外国键的支持,我只是执行一个SQL语句,使外键的支持。 e.g。

        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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top