0

I have been using Sql Server with EF Core and I was able to do something like this ctx.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Persons ON"); to explicitly set entity id during insert. I was using it for my tests.

Now I am working with Oracle database with devart provider and I dont know how to do the same thing. Is there a way to do this with Oracle?

Aleksa
  • 2,976
  • 4
  • 30
  • 49
  • How is your table defined? If you have an identity column (i.e. `CREATE TABLE table_name ( id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY )`) then it might be difficult. – MT0 Nov 20 '20 at 00:32
  • What are you using for the primary key in Oracle, probably you are using sequences. If the question is yes, then you don't need to use this command or some similar. https://stackoverflow.com/questions/51470/how-do-i-reset-a-sequence-in-oracle – Emin Mesic Nov 20 '20 at 06:07

1 Answers1

0

With GENERATED BY DEFAULT ON NULL, Oracle will insert the value you provide into the identity column. If no value or it is NULL, a value for the identity column will be generated by Oracle.

CREATE TABLE demo_table (
    id NUMBER GENERATED BY DEFAULT ON NULL,
    description VARCHAR2(100) NOT NULL
);
Devart
  • 119,203
  • 23
  • 166
  • 186