Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework : Manually set an "Identity" value

I am currently using the entity-framework with SQLite. I am currently inserting entity with an ID (that is autogenerated by SQLite but it is not autoincrement'ed. See this). This field is marked as StoreGeneratedPattern = "Identity" in the .edmx.

I would like to insert entity in the table and be able to specify an ID (so the database won't have to generate one).

like image 774
Drahakar Avatar asked Jul 18 '26 03:07

Drahakar


1 Answers

Once the field is configured with StoreGeneratedPattern.Identity you cannot modify it in the application. That is how it works. If you try to do it EF will either skip your modification or throws exception. If you need to define key on the client you don't have to generate key in the database and you must set StoreGeneratedPattern.None.

like image 175
Ladislav Mrnka Avatar answered Jul 19 '26 16:07

Ladislav Mrnka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!