Remove creation of serial column EntityFramework + Npgsql

2

Hello, I'm creating an application using Fluent API + Entityframework. However in my domain classes when determining that a property is PK it automatically defines it as serial, I would not like to get this behavior because it will automatically create a SEQUENCE for each PK field in my tables. How do I remove this validation and define that when the field is primary key I do not want it to be serial and only integer?

Thank you

    
asked by anonymous 25.10.2016 / 03:30

1 answer

1

You need to mark the column to not generate the sequential. This should resolve for you:

modelBuilder
    .Entity<*nome_da_entidade*>()
        .Property(m => m.*campo*)
             .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

Another way I imagine it to be automatic would be to include the attribute below directly in the property:

[System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(
    System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None)]

Or, better, add System.ComponenteModel.DataAnnotations.Schema to your using clauses and just look like this:

[DatabaseGenerated(DatabaseGeneratedOption.None)]
    
25.10.2016 / 05:24