众所周知,SQLite 可以为外键设定 Reactions 以支持在对外键数据编辑、删除的时候进行级联操作。但在使用 SqlSugar ORM 时(内部使用 System.Data.SQLite 库),构建的 SQL 语句在执行时却无法使 Reactions 定义生效。

    实际上,在 SQLite Delete Cascade not working 的回答中,有对该现象原因的描述: SQLite defaults to PRAGMA foreign_keys = OFF every time you open the database. It’s not a property of a table or of the schema.

    Foreign key support in sqlite3 的回答中有明确的解决方案: Try including > foreign keys=True property in your connection string.

    即连接字符串应为:data source=filename;foreign keys=true;,如此便可在代码中启用对 Reactions 的支持了。