在Entity Framework Core 1.0 RC2(以前的Entity Framework 7 RC2)中,默认情况下,所有整数主键都是自动增量字段。我尝试了一切来删除它。从使用数据注释到流畅的API,没有任何作用。
使用数据注释:
[Key, Column(Order = 1, TypeName = "INT"), DatabaseGenerated(DatabaseGeneratedOption.None)]
使用流利的API:
modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId).HasAnnotation("DatabaseGenerated", DatabaseGeneratedOption.None);
//OR use the following
modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId).HasAnnotation("DatabaseGenerated", 0);
//OR use the following
modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId).HasAnnotation("Sqlite:Autoincrement", false);
没有任何效果:(
你能帮帮我吗?
如已请求,这是我在运行添加迁移LocalDB_v1
后获得的表脚本migrationBuilder.CreateTable(
name: "tblProduct",
columns: table => new
{
ProdId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_tblProduct", x => x.ProdId);
});
...
...
...
答案 0 :(得分:12)
在EF Core中,d3。
指定密钥:
modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId);
配置属性不是自动增量:
modelBuilder.Entity<tblProduct>().Property(t => t.ProdId).ValueGeneratedNever();
答案 1 :(得分:0)
我没有使用EF 7,但很少检查