0

I have the following model:

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public string Id { get; set; }

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int OrderNumber { get; set; }

I would like OrderNumber to increment by 1 every time. However for some strange reason I get the following sequences: 1,2,3,4,..., 75, 1075, 1076, 1077, 1078,..., 1086, 2086, 2087, 2088,...

For some strange reason they go in a sequence incrementing by one but every now and then it jumps with 1000.

I would appreciate if anyone can point me in the right direction for debugging.

mgPePe
  • 5,677
  • 12
  • 52
  • 85
  • 1
    That is unrelated to C#/Entity Framework. Take a look at: https://stackoverflow.com/questions/14162648/sql-server-2012-column-identity-increment-jumping-from-6-to-1000-on-7th-entry – Camilo Terevinto Sep 27 '21 at 13:11
  • 2
    Note that even without this weird behaviour identity is not guaranteed to not have gaps (say if transaction fails for whatever reason - id will not be reused later). – Evk Sep 27 '21 at 13:20
  • which is the primary key? Id or OrderNumber? – Ramakrishnan Sep 27 '21 at 13:36
  • @Ramakrishnan the primary is the `Id`, which is not the issue I am having trouble. – mgPePe Sep 27 '21 at 15:25
  • thanks @CamiloTerevinto, I ended up removing that logic and simply implementing my own numbering – mgPePe Sep 27 '21 at 15:27
  • @mgPePe As long as you ensure it's done in a database transaction atomically, it should all be good :) – Camilo Terevinto Sep 27 '21 at 15:28
  • MySQL's `AUTO_INCREMENT` does not have jumps _like that_. Please provide `SHOW CREATE TABLE`; I suspect you are looking the wrong place. – Rick James Sep 28 '21 at 01:24

0 Answers0