Jumping id 1000 Sql server 2014 (localDB)

Asked

Viewed 115 times

1

In my application a few times when I will add some data to the database the ID jumps in 1000 drives.

I found some solutions, but they are not good for me because I use EF6 with code-first and my intention is to install the application with Localdb on a machine without "programming components".

What would help me solve this?

Example class:

 public class ProdutoDTO
    {
        public int produtoID { get; set; }
        public int codigo { get; set; }
        public string descricao { get; set; }
        public decimal preco { get; set; }
        public DateTime dataCadastro { get; set; }
    }

Mapping:

class ProdutoConfig : EntityTypeConfiguration<ProdutoDTO>
    {
        public ProdutoConfig()
        {
            HasKey(p => p.produtoID);

            Property(p => p.descricao)
                .IsRequired()
                .HasMaxLength(100);

            Property(p => p.preco)
                .IsRequired();
        }
    }

In the project I use: Code first, EF6, Migrations, generic repositories, implementation repositories and mapping with Fluent Api.

  • 1

    As so it is jumping 1000, it would not be a table that has already been created and you are performing several operations without resetting Identity?

  • Type, the last product table id is 7, hence I will add another product and instead of id being 8 it becomes 1008

  • 1

    always 1000 range? see how’s the table auto increment setting

  • Yes, always 1000

  • 1

    Display your entity class and your table’s Identity configuration

  • Edit on the question, is this your entity model or just a actual DTO? Checked if Seed is not set to 1000?

  • I separated into 3 layers and decided to use DTO, so basically this is my template class for table creation

  • I edited the question

  • And the Identity Seed?

  • How I see the Seed setting?

  • Run this query in the & #Xa database;SELECT IDENT_SEED(TABLE_NAME) AS Seed, IDENT_INCR(TABLE_NAME) AS Increment,IDENT_CURRENT(TABLE_NAME) AS Current_Identity&#xA;FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Produto'

  • Seed : 1 Increment: 1 Current_identity : 2001

  • 1

    Take a look here https://stackoverflow.com/questions/39671899/ids-jumping-up-1000-every-time-i-build-my-app-and-insert-a-new-record

  • 3

    Possible duplicate of SQL increasing ID by 1000 units

  • 2

    @Leandroangelo and Márcio answered an item related to this one: https://answall.com/questions/36881/sql-incrementing-o-id-em-1000-unidades/36890#36890

  • 1

    @Renan Boa, killed the riddle.

  • 1

    Thank you very much to the 2, I will see that now, I think it solves my problem

  • 1

    It is an error of SQL Server, usually happens in case of database failures. It has a parameter that should be placed on the service startup, so that the database creates the identity log, avoiding the loss of sequence during failures. check this link, it has the complete dossier : http://www.dfarber.com/computer-consulting-blog/2014/2/13/how-to-solve-identity-problem-in-sql-2012/

Show 13 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.