gpt4 book ai didi

c# - 使用 SQLite 和 C# 强制外键约束

转载 作者:行者123 更新时间:2023-12-03 19:13:14 24 4
gpt4 key购买 nike

我创建了一个外键约束 ON DELETE 设置默认 在数据库中,我分配了一个默认值。

我尝试了什么:

  • 在 App.Config 中:我在连接字符串中添加了“ foreign keys=true; ”。
  • I edited the dataset XSD
  • 我更改了 WinForm 上的 DataSet 并在那里强制执行:强制约束 = 真
  • 我查了一下,我的 SQLite 版本足够高,可以支持这个(我使用 v1.0.110.0)
  • 我不能使用 PRAGMA 命令(如下所示: Enabling Foreign key constraints in SQLite ),因为数据绑定(bind)到控件。
  • 我重建了项目。
  • 我在 SqliteStudio 中尝试过,并且约束有效,但在 C# 中却没有。

  • 我可能错过了什么......

    更新:
    App.Config 以某种方式与项目设置不同步,因此额外的参数不包含在构建中。但是,通过项目属性添加参数会引发错误。
    "Data Source=.\InventoryManagerDatabase.db;foreign keys=true;" 

    错误:

    System.InvalidOperationException: 'Unknown connection string parameter 'foreign keys'.'



    显然这个参数不存在?我检查了各种资源,包括 Enabling Foreign key constraints in SQLite & SQLite EF6 programmatically set connection string at runtime但这很奇怪... SQLite 是否删除了此参数或重命名了它?

    我也尝试过(以及区分大小写的组合):
    EnforceFKConstraints=True;
    foreign key=true;
    foreign keys=true;
    foreign_keys=true;
    ForeignKeys=true;
    Foreign Key Constraints=true;
    PRAGMA foreign_keys = ON; // obviously does not work

    但是没有任何效果...

    最佳答案

    终于找到了!

    解决方案:

    connectionString="Data Source=.\YourDatabaseName.db;Foreign Key Constraints=On;Version=3;"

    是的,他们在某处将其更改为 外键约束=打开 谷歌上的每个页面,包括 StackOverflow 仍然显示旧参数......

    关于c# - 使用 SQLite 和 C# 强制外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55709635/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com