Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using identity column and DataSeeding with Oracle.EntityFrameworkCore

User_PXVVZApr 28 2021

Hi all,
at first my system environment and the used versions:
Windows 10
Oracle XE 18.0.0
Oracle.EntityFrameworkCore 3.19.80
.Net Core 3.1

Now my probIem:
Imagine a simple table USER with just an ID and NAME column (just for example). I want to use ID as an identiy column. I also want to seed data using ef migration for the USER table. Everything works fine, except for the problem, that the generated sequence of the ID column is not adjusted to the correct next value after the data is seeded, it just sticks at <SEQUENCE>.LAST_NUMBER = 1.
A bit code:
Code.PNG
I'm a bit limited by the following requirements:
I have to keep the model and the creating very simple, cause I have to use the context also for a SQLite-DB (for internal tests)
I can't use explicite sequences, because SQLite can't handle them
I have to set the Ids explicitly in the data seeding, because I need them for other seeds/data
I can't use negative Ids for data seeding
A solution within .Net/code is necessary (so a simple sql scripte that is executed to alter the sequences/tables after the database is deployed is not good)

=> To sum up: My question is, is there a way to automatically adjust the seuqence (in the modelBuilder) after the data seeded? SqlServer is able to do it, but Oracle seems not to be able to. Or am I missing something in the model creation?
P.S.: Maybe the GENERATED BY DEFAULT ON NULL is the problem, but I didn't find a way to change this in ef core.

Comments
Post Details
Added on Apr 28 2021
9 comments
2,068 views