4

I am using a Firebird 2.1 database together with VS2010 (.NET 4.0) and am trying to get it to work properly with the entity framework.

The problem is, that when I generate an entity from a database table, the framework detects all columns to be part of the primary key. The table is very simple with two integer columns, one of them being set as primary key.

I even have "#PK_GEN#" set as comment of the primary key column.

In the EF-Editor I cannot modify the primary key property of the store object, and since I will have to deal with nullable columns, that is a problem. I can edit the XML code of the model file, but the changes are non-persistent when updating the model, so that is a show-stopper.

Since I only read about similar problems concerning views not tables, I am obviously doing something wrong, but I can't figure it out.

edit: By the way, I just tested the behavior with VS 2012 and it remains unchanged.

Here's the CREATE script. Since I'm new to Firebird, there might me something wrong here as well, but I really don't think so.

CREATE GENERATOR GEN_TESTTABLE_ID;
CREATE TABLE TESTTABLE (
    TESTTABLE_ID  INTEGER NOT NULL,
    VALUE         INTEGER
);
ALTER TABLE TESTTABLE ADD CONSTRAINT PK_TESTTABLE PRIMARY KEY (TESTTABLE_ID);
COMMENT ON COLUMN TESTTABLE.TESTTABLE_ID IS '#PK_GEN#';

SET TERM ^ ;
CREATE OR ALTER TRIGGER TESTTABLE_BI_GEN_ID FOR TESTTABLE
ACTIVE BEFORE INSERT POSITION 0
AS
begin
  if ((new.testtable_id is null) or (new.testtable_id = 0) ) then
    begin
      new.testtable_id = gen_id(gen_testtable_id, 1);
    end
end
^
SET TERM ; ^
Julian
  • 55
  • 3
  • 1
    Maybe a stupid question, but you marked the column as autogenerated (identity), but did you also make it the primary key? – Gert Arnold Feb 28 '13 at 21:33
  • yes, I set up one column as primary key and a BeforInsert trigger generates a new id, if needed. Looks like a pretty straight forward table to be, just like I would do it in MS SQL Server or Oracle -- apart from how the ID's are generated. Just in case, I'll add the CREATE TABLE statement to the question tomorrow... – Julian Mar 01 '13 at 22:09

1 Answers1

2

Problem is, that Firebird 2.1 contains a bug, that results in this. Generate the model using Firebird 2.5 and you'll be fine.

Some references here, here, here.

cincura.net
  • 4,130
  • 16
  • 40
  • Thanks for your answer. I can indeed confirm, that the problem does not occur for Firebird 2.5. – Julian Mar 07 '13 at 06:41