外键自动增量在 sqlite .NET 提供程序中不起作用
我将多个数据插入到 sqlite 表中,并始终获得相同的 ID。但字段Id配置为PK+autoinc Id。
我使用它作为连接字符串:
public static void SetConnectionString(string dataDataAccessPath)
{
_connectionString = String.Format(@"Data Source={0};Foreign Keys=ON", dataDataAccessPath);
}
除了“PRAGMAforeign_keys = ON;”之外,还为连接实现了“Foreign Keys=ON”必须为每个打开的连接执行该操作。
现在我想知道为什么连接字符串上的新属性不起作用......
我有什么问题吗?
I insert multiple data into a sqlite table and get always the same ID back. But the field Id is configured as PK + autoinc Id.
I use this as connection string:
public static void SetConnectionString(string dataDataAccessPath)
{
_connectionString = String.Format(@"Data Source={0};Foreign Keys=ON", dataDataAccessPath);
}
This "Foreign Keys=ON" was implemented for the connection besides the "PRAGMA foreign_keys = ON;" which had to be executed for every opened connection.
Now I wonder why the new attribute on the connectionstring does not work...
Do I something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 SQLite 方面的专家(事实上我没有实践经验),但我想你的 IDENTITY 字段是否会随着插入而自动增加与定义有更多关系表的内容与您正在使用的连接字符串的内容相比。
请注意,您本身无法增加
FOREIGN KEY
,而是需要使用充当PRIMARY KEY
的IDENTITY
字段来增加表> 然后FOREIGN KEY
引用。您可以添加您遇到问题的表的定义吗?
I'm not an expert on SQLite (in fact I have no practical experience with it) but I would imagine that whether or not your
IDENTITY
fields automatically increment with your insert has something to do more with the definition of the table than with the connection string you are using.Be reminded that you cannot increment a
FOREIGN KEY
per se, but rather you need to increment the table with theIDENTITY
field that serves as thePRIMARY KEY
that theFOREIGN KEY
then references.Can you add the definition of the table that you are having trouble with?