How to configure the IncrementBy of a PostGreen Id field using the Entity Framework Core

0

I have a table mapped to PostGre, but when I update the database, the PersonFisicaEnderecoTipoId Field is being auto-incremented by 10 (by default). How do I map so that IncrementBy is set to autoincrement by 1 in 1?

TableMapping:

publicclassPessoaFisicaEnderecoTipoMap:IEntityTypeConfiguration<PessoaFisicaEnderecoTipo>{publicvoidConfigure(EntityTypeBuilder<PessoaFisicaEnderecoTipo>builder){builder.ToTable("PessoaFisicaEnderecoTipo");

        builder.HasKey(pfet => pfet.Id);

        builder.Property(pfet => pfet.Id)
            .HasColumnName("PessoaFisicaEnderecoTipoId")
            .ForNpgsqlUseSequenceHiLo()
            .IsRequired();

        builder.Property(pfet => pfet.Descricao)
           .HasColumnName("Descricao")
           .HasColumnType("character varying(50)")
           .IsRequired();

        builder.Property(pfet => pfet.PadraoSistema)
          .HasColumnName("PadraoSistema")
          .HasColumnType("boolean");

    }


}
    
asked by anonymous 30.11.2018 / 19:15

1 answer

1

The sequence of 10 in 10 is the default when you are using ForNpgsqlUseSequenceHiLo . You can create your custom sequence 1 in 1 and enter as below:

modelBuilder.HasSequence("minha_sequencia", b => b.IncrementsBy(1))    

builder.Property(pfet => pfet.Id)
    .HasColumnName("PessoaFisicaEnderecoTipoId")
    .ForNpgsqlUseSequenceHiLo("minha_sequencia")
    .IsRequired();
    
31.12.2018 / 12:43