I have a question about the Behavior of Entity Framework when SaveChanges
method is executed.
I have an entity that has an Identity Column, and just realize that when if I call SaveChanges
(for a new insert), and it fails then my Identity Column in my DB is increased.
I used to have the Identity column value equals 7, and I was debugging my code and SaveChanges
method failed 5 times, because I missed to insert a required value, and when it worked out I noticed that my identity column value was now 13.
Is this a normal behavior? Is there a way to avoid increasing identity column value when Entity Framework fail to do a commit into my DB?
Appreciate any help
This is Sql's behaviour and not Entity Framework.You should have a look at Dbreseed command and execute it for your table if you don't want to Identity to be wasted.check this So question RESEED identity columns on the database If I were you I wouldn't have bothered.Instead just use Bigint datatype for the identity column
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With