Disabling identity (auto-incrementing) on integer primary key using code first

后端 未结 7 1350
孤街浪徒
孤街浪徒 2020-12-01 10:13

I am using code first approach in a ASP.NET MVC 3 application and all integer primary keys in models (public int Id { get; set; }) are by default configured as

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 10:42

    If you want to use fluent api with EntityFramework Core 2.0 you write:

    modelBuilder.Entity<*myEntity*>()
      .Property(e => e.*myFieldname*)
      .ValueGeneratedNever();
    

提交回复
热议问题