I have a table in EntityFramework that has a field named by ID, this field is primary key and is Identity. when i add records into this table, this field value increases per recor, after adding several records, this value suddenly increases For example, increased from 90 in 1010 While no transaction has been unsuccessful. what is the problem?
Asked
Active
Viewed 81 times
5
-
1This field has this property: [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated (System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)] – Deve loper Jun 05 '16 at 04:52
-
1Make sure the seed for your field is set to just 1. – Hanlet Escaño Jun 05 '16 at 04:55
-
1@Hanlet Escaño yes is set to 1 – Deve loper Jun 05 '16 at 05:04
-
1How do you add the records? Show us some code pls. – Hanlet Escaño Jun 05 '16 at 05:05
-
1for example : dbContext.TableName.add(object); and then : dbcontext.SaveChanges() – Deve loper Jun 05 '16 at 05:11
-
1I just wanted to see more _how_ you actually implement it (is it inside a loop for example). – Hanlet Escaño Jun 05 '16 at 05:12
-
1oh, no. Records simply added to table in a transaction, with any loop. – Deve loper Jun 05 '16 at 05:19
-
1Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113829/discussion-between-hanlet-escano-and-deve-loper). – Hanlet Escaño Jun 05 '16 at 05:26
1 Answers
0
If you are using Azure SQL this can just happen. We had it happen a few times. It is just the nature of how Azure sql works.
See this question Windows Azure SQL Database - Identity Auto increment column skips values it goes into a detailed explanation for a case very similar to yours

Community
- 1
- 1

GraemeMiller
- 11,973
- 8
- 57
- 111