DBMetal (SQLite):“序列包含多个元素”有多个外键

发布于 2024-09-10 02:30:07 字数 800 浏览 1 评论 0原文

当尝试使用 DbMetal(作为 DbLinq 的一部分)创建 C# 文件时,出现以下错误:

DbMetal:序列包含多个元素

仅当我引用多个外键作为主键的一部分时才会出现。以下是导致问题的表的 DDL:

CREATE TABLE [QuestionChoice] 
(
    [QuestionaireID] INTEGER NOT NULL,
    [QuestionNumber] INTEGER NOT NULL,
    [ChoiceNumber] INTEGER NOT NULL,
    [Wording] VARCHAR
    (
        100
    )
    NOT NULL,
    PRIMARY KEY 
    (
        [ChoiceNumber],
        [QuestionNumber],
        [QuestionaireID]
    ),
    FOREIGN KEY 
    (
        [QuestionNumber],
        [QuestionaireID]
    )
    REFERENCES [Question]
    (
        [QuestionNumber],
        [QuestionaireID]
    )
)

我用来设置 SQLite 数据库的工具是 SQLite Studio。我设置了一个表约束来设置外键。

如果我单独设置外键(每个项目)而不是作为表约束,则生成的类具有对 Question 表的多个引用,从而在尝试插入表时导致多个引用和错误。

When trying to create a C# file using DbMetal (as part of DbLinq), I get the following error:

DbMetal: Sequence contains more than one element

It's only appearing when I reference multiple foreign keys as part of my primary key. The following is the DDL for my table causing issues:

CREATE TABLE [QuestionChoice] 
(
    [QuestionaireID] INTEGER NOT NULL,
    [QuestionNumber] INTEGER NOT NULL,
    [ChoiceNumber] INTEGER NOT NULL,
    [Wording] VARCHAR
    (
        100
    )
    NOT NULL,
    PRIMARY KEY 
    (
        [ChoiceNumber],
        [QuestionNumber],
        [QuestionaireID]
    ),
    FOREIGN KEY 
    (
        [QuestionNumber],
        [QuestionaireID]
    )
    REFERENCES [Question]
    (
        [QuestionNumber],
        [QuestionaireID]
    )
)

The tool I'm using to setup my SQLite database is SQLite Studio. I set a table constraint to set the foreign keys.

If I set the foreign keys seperately (per item) instead of as a table constraint, the generated classes have multiple references to the Question table, causing multiple references and errors when trying to insert into the table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2024-09-17 02:30:07

为了解决这个问题,我采纳了 Stephen Cleary 在评论中的建议,并对所有表使用了一个INTEGER PRIMARY KEY。看来虽然 SQLite 可能支持多个外键,但 DBMetal 对这个想法感到窒息。

因此,另一个表的外键会产生单个引用,并且 DBMetal 会适当地处理所有内容。

To solve the issue, I took Stephen Cleary's suggestion in the comments, and used a single INTEGER PRIMARY KEY for all tables. It appears that while SQLite may support multiple foreign keys, DBMetal chokes on the idea.

As a result, a foreign key to another table results in a single reference, and DBMetal handles everything appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文