如何让 EntityTypeBuilder 以新的方式放置正确的注释?

How to make EntityTypeBuilder put right comments in new way?

我在我的项目中使用 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"。 如何解决此问题?

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

已经修复,但遗憾的是该修复将在 3.1 版本中可用。

在那之前你无能为力。