[英]EF Code First - Identity is always on
I am using Code first and my ID column looks like this: 我首先使用代码,我的ID列如下所示:
[Key]
[Required]
public int ID { get; set; }
Am trying to cancel the identity of some tables and cannot do it. 我试图取消某些表的身份,但无法这样做。 I am using Fluent API:
我正在使用Fluent API:
.Property(b => b.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
and the generated code is of migration is: 生成的代码具有移植性:
public override void Up()
{
AlterColumn("MyEntity", "ID", c => c.Int(nullable: false,
identity: false));
}
public override void Down()
{
AlterColumn("MyEntity", "ID", c => c.Int(nullable: false,
identity: true));
}
But it doesn't change in the db. 但是它在数据库中没有改变。 Any ideas please?
有什么想法吗?
you can do it using data annotations. 您可以使用数据注释来做到这一点。
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ID { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.