0

我想让数据库自动生成 Ancora_id 属性。我使用了数据注释,但它不起作用。我将向您展示 Ancora 模型和 Db_context 中的代码。

字段 ancora_id 它不是我的表的主键,作为主键,我有另一个 Guid 类型的字段,称为 Id。

谁能告诉我我错在哪里?

public partial class Ancore: EntityDb
{

[Key]
public Guid Id {get; set; }

[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public Int64 Ancora_id { get; set; }

}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
            modelBuilder.HasAnnotation("Relational:Collation", "Latin1_General_CI_AS");

modelBuilder.Entity<Ancore>(entity =>
{
entity.ToTable("Ancore");

entity.Property(e => e.Id)
      .ValueGeneratedNever()
      .HasColumnName("id");

entity.Property(e => e.Ancora_id).HasColumnName("ancora_id");

});
}
4

0 回答 0