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

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
J.Gall
Posts: 7
Joined: Fri 21 Nov 2014 08:41

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

Post by J.Gall » Fri 21 Nov 2014 08:54

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

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

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

Post by MariiaI » Fri 21 Nov 2014 13:11

We have contacted you by e-mail.

J.Gall
Posts: 7
Joined: Fri 21 Nov 2014 08:41

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

Post by J.Gall » Fri 21 Nov 2014 15:50

Can you resend me the E-Mail please, i have actually nothing received. Thank's

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

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

Post by MariiaI » Mon 24 Nov 2014 06:22

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.

J.Gall
Posts: 7
Joined: Fri 21 Nov 2014 08:41

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

Post by J.Gall » Mon 24 Nov 2014 09:06

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

Post Reply