在EntityFrameworkCore1.0 RC2 (前实体框架7 RC2)中,默认情况下,所有的整数主键都是自动增量字段。我用尽一切办法把它移除。从使用数据注释到fluent API,什么都不起作用。
使用数据注释:
[Key, Column(Order = 1, TypeName = "INT"), DatabaseGenerated(DatabaseGeneratedOption.None)]使用fluent 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);什么也没起作用
你能帮帮我吗?
已更新
按照要求,下面是在运行add- 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);
});
...
...
...发布于 2017-01-28 12:47:33
在EF核心,key and property are configured separately。
若要指定密钥,请执行以下操作:
modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId);若要配置非自动增量的属性,请执行以下操作:
modelBuilder.Entity<tblProduct>().Property(t => t.ProdId).ValueGeneratedNever();发布于 2017-01-28 09:51:08
我没有和EF 7一起工作,但是没有几个点需要检查。
https://stackoverflow.com/questions/41908391
复制相似问题