Page 1 of 1

Code First approach - DEFAULT_VALUE for table columns using existing sequence in DB

Posted: Fri 21 Nov 2014 08:54
by J.Gall
Hi,

In our application we are using EntityFramework 6.1 with code first and the Devart dotConnect Data Provider v8.4.264.6 for Oracle. I have a question regarding the DEFAULT_VALUE for table columns. I found an example solving this issue when using EntityFramework with the model first approach here: http://blog.devart.com/set-identity-and ... ggers.html .

We are looking for a similar solution with Devart dotConnect for the code first approach.

Right now we have an Oracle database (version 11g) and would prefer to use only the existing sequence for generating of identity (ID) column value, without having to use the trigger defined in the Oracle database.
Is this possible with dotConnect and the code first approach?

Regards
Jaroslav

Re: Code First approach - DEFAULT_VALUE for table columns using existing sequence in DB

Posted: Fri 21 Nov 2014 13:11
by MariiaI
We have contacted you by e-mail.

Re: Code First approach - DEFAULT_VALUE for table columns using existing sequence in DB

Posted: Fri 21 Nov 2014 15:50
by J.Gall
Can you resend me the E-Mail please, i have actually nothing received. Thank's

Re: Code First approach - DEFAULT_VALUE for table columns using existing sequence in DB

Posted: Mon 24 Nov 2014 06:22
by MariiaI
We are looking for a similar solution with Devart dotConnect for the code first approach.
Unfortunately, it is impossible to do directly with the Code-First approach. The possible solutions are:
1) You can open the connection before calling SaveChanges(), use the necessary sequences and set their values for the necessary entity properties manually.
2) If it is possible, use the RAW(16) datatype for PK and generate its value on the client side as Guid.NewGuid().ToByteArray().
3) Use Oracle 12c: starting from the Oracle 12c the possibility to use identity instead of sequences and triggers is available.

Re: Code First approach - DEFAULT_VALUE for table columns using existing sequence in DB

Posted: Mon 24 Nov 2014 09:06
by J.Gall
Hallo Mariial,

I thing we use a Oracle trigger. This will only fired if the PK is NULL or 0. We have old and new SW version of our software working with the same database and I think, this is the best solution for this problem.

CREATE OR REPLACE TRIGGER PROD_INS_TRG
BEFORE INSERT ON "PROD" FOR EACH ROW
BEGIN
IF (:NEW.ID IS NULL) OR (:NEW.ID = 0) THEN
SELECT PROD_ID_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
END IF;
END;

Thank's for you response & have a nice day.

Best Regards
Jaroslav