Disabling identity (auto-incrementing) on integer primary key using code first
use attribute :
public class MessageSubject
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Title { get; set; }
public string Comment { get; set; }
public bool BuildIn { get; set; }
}
Use these data annotation options:
[System.ComponentModel.DataAnnotations.KeyAttribute()]
[System.ComponentModel.DataAnnotations.DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.None)]
You can use FluentMapping:
modelBuilder.Entity<*entityname*>().Property(m => m.*fieldname*)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
If you want to use fluent api with EntityFramework Core 2.0 you write:
modelBuilder.Entity<*myEntity*>()
.Property(e => e.*myFieldname*)
.ValueGeneratedNever();