Page 1 of 1

Entity Framework INSERT operations

Posted: Fri 20 Aug 2010 15:32
by i.kopcanski
We have trigger defined on the table to have auto increment ID column:

[code]
create or replace TRIGGER "V2_ACTIVE_USERS"
BEFORE INSERT ON "V2_ACTIVE_USERS"
FOR EACH ROW
DECLARE
LAST_SEQUENCE NUMBER;
LAST_INSERTID NUMBER;
BEGIN
IF (:NEW."ID" IS NULL)
THEN SELECT "V2_ACTIVE_USERS_0".NEXTVAL INTO :NEW."ID" FROM DUAL;
ELSE SELECT LAST_NUMBER-1 INTO LAST_SEQUENCE
FROM USER_SEQUENCES WHERE UPPER(SEQUENCE_NAME) = UPPER('V2_ACTIVE_USERS_0');
SELECT :NEW."ID" INTO LAST_INSERTID FROM DUAL;
WHILE (LAST_INSERTID > LAST_SEQUENCE)
LOOP
SELECT "V2_ACTIVE_USERS_0".NEXTVAL INTO LAST_SEQUENCE FROM DUAL;
END LOOP;
END IF;
END;
[/code]

When that table is dragged and dropped in EF model,
and when INSERT operation is performed by using
generated code from EF model, the exception occurs
related to ORA-04088 (error in trigger execution).

When perfoming simle INSERT query on the same table
on Oracle database manually without specifying id column
it works ok:

[code]
INSERT INTO V2_ACTIVE_USERS(LOGIN_NAME, LICENSE_LEVEL, LAST_ACTIVITY)
values ('i.kopcanski', 0, '13-AUG-2010')
[/code]

but this query fails with the same error code:

[code]
INSERT INTO V2_ACTIVE_USERS(ID, LOGIN_NAME, LICENSE_LEVEL, LAST_ACTIVITY)
values (6, 'i.kopcanski', 0, '13-AUG-2010')
[/code]

So, it is obvious that EF model craeted by .dotConnect for Oracle
plug-in generates the INSERT query with specifying ID column
not understanding that it should be auto increment column.
Maybe it should be specified somehow in the model itself that
this ID column is auto-incremental.

Can you help us with this issue?

Posted: Sat 21 Aug 2010 12:02
by Shalex
Please make sure that the ID property in your SSDL contains the StoreGeneratedPattern="Identity" attribute (right click on your *.edml in Solution Explorer > Open With > XML Editor). You can also set this attribute in Entity Developer: select the ID column in Model Explorer and set its Store Generated Pattern property to Identity.

For more information, please refer to:
1) MSDN: http://msdn.microsoft.com/en-us/library ... ttern.aspx;
2) Devart Entity Developer Documentation: Entity Framework > Concepts > Columns | Store Generated Pattern.