如何使EntityTypeBuilder用新的方式添加正确的注释?

时间:2019-11-08 11:08:21

标签: c# database-migration npgsql ef-core-3.0

我在项目中使用Npgsql.EntityFrameworkCore。我这样配置我的实体:

internal class MyEntityConfiguration : IEntityTypeConfiguration<MyEntity>
{
    public void Configure(EntityTypeBuilder<MyEntity> builder)
    {
        builder.HasComment("Entity description");

        builder.Property(e => e.Name)
            .IsRequired()
            .HasMaxLength(255)
            .HasComment("Name of entity");

        builder.Property(e => e.IsActual)
            .HasComment("Is entity actual");
    }
}

由于ForNpgsqlHasComment已过时(并且可以正常工作),我们应该使用HasComment,这会导致错误的迁移:

migrationBuilder.CreateTable(
    name: "MyEntity",
    columns: table => new
        {
            Id = table.Column<int>(nullable: false)
                      .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
            Name = table.Column<string>(maxLength: 255, nullable: false, comment: "Entity description"),
            IsActual = table.Column<bool>(nullable: false, comment: "Entity description")
        },
    comment: "Entity description");

换句话说,在所有注释中使用"Entity description"。 如何解决此问题?

1 个答案:

答案 0 :(得分:0)

这是一个3.0错误#17474: Entity comments overwrites property comments

已经修复,但是不幸的是,该修复程序将在3.1版本中提供。

在那之前您无能为力。