Search code examples
c#database-migrationnpgsqlef-core-3.0

How to make EntityTypeBuilder put right comments in new way?


I use Npgsql.EntityFrameworkCore in my project. I configure my entity like this:

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");
    }
}

since ForNpgsqlHasComment is obsolete (and actually work fine) and we should use HasComment, which makes wrong migration:

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");

in other words, uses "Entity description" in all comments. How to fix this behavior?


Solution

  • It's a 3.0 bug #17474: Entity comments overwrites property comments.

    Already fixed, but unfortunately the fix will be available in 3.1 release.

    Until then there is nothing you can do.