我已经修改了System.Data.SQLite以使用最新版本的SQLite引擎,该引擎无需使用自定义触发器即可自动实施外键。
我也在使用SubSonic 2.x,但这将适用于任何使用SQLite的ORM框架,这些框架是“开放晚,关闭早”的。
如何确保在每个SQLiteConnection.Open()上都会调用'PRAGMA foreign_keys=true‘语句?它必须被调用,否则外键将不起作用。
发布于 2009-12-02 04:37:34
为了解决这个问题,我在SQLiteConnection类的ConnectionString中添加了一个“外键”属性。
外部Keys=ON外部Keys=OFF
发布于 2009-12-17 00:07:05
如果您想使用最新版本的SQLite,则不需要修改System.Data.SQLite,只需使用ManagedOnly版本的System.Data.SQLite,然后只用最新版本替换sqlite3.dll即可。为了启用外键支持,我只需执行一条启用外键支持的sql语句。例如:
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();https://stackoverflow.com/questions/1823537
复制相似问题