Entity, Oracle and Identiity Column Architecture

I am using Entitiy Framework with Oracle and I use sequences when I need autogenerated primary key columns. When I create an edmx project, the EF designer does not recognize this pattern, so I need to insert StoreGeneratedPattern = "Identity" into the edmx file manually for all identitiy columns. I repeat this every time I need to update my model. When the model gets large and frequent updates often become labor intensive.

I wonder if there is a simpler method, for example, the first time I add a table to the model, I can add the storeGeneratedPattern = "Identity" line to the edmx, but automatically add this line after updates.

+3


source to share


1 answer


In Oracle 12c, you have an identity column.

SQL> drop table identity_table purge
  2  /

Table dropped.

SQL>
SQL> CREATE TABLE identity_table (
  2    ID          NUMBER GENERATED ALWAYS AS IDENTITY,
  3    txt        VARCHAR2(30)
  4  )
  5  /

Table created.

SQL>
SQL> INSERT INTO identity_table(txt) VALUES('id number 1');

1 row created.

SQL> INSERT INTO identity_table(txt) VALUES('id number 1');

1 row created.

SQL> INSERT INTO identity_table(txt) VALUES('id number 1');

1 row created.

SQL>
SQL> SELECT * FROM identity_table;

        ID TXT
---------- ------------------------------
         1 id number 1
         2 id number 1
         3 id number 1

SQL>

      



Oracle actually creates a sequence for you, all you have to do is create an identity column NUMBER GENERATED ALWAYS AS IDENTITY

.

0


source







All Articles