views:

46

answers:

1

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.

A: 

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.

Will Eddins