.Ignore() 在迁移到 EFCore 3.1 后抛出异常

.Ignore() throwing exception after migration to EFCore 3.1

我在迁移到 EFcore 3.1(迁移前使用 2.2)之前让这段代码正常工作,现在它抛出以下异常:'The type 'ProfileEnum' cannot be configured as non-owned because an owned entity type with the same name already exists.'

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
     modelBuilder.ApplyConfiguration(new UserConfig());

     modelBuilder.Entity<ProfileEnum>()
            .Ignore(p => p.Name);
}

场景是:ProfileEnum 是一个复杂类型,我使用以下块

映射到用户 class
public class UserConfig : IEntityTypeConfiguration<User>
{
    public void Configure(EntityTypeBuilder<User> builder)
    {
        builder.HasKey(x => x.UserId);

        builder.Property(x => x.Name)
            .HasMaxLength(200);

        builder.Property(x => x.DocumentNumber)
            .HasMaxLength(50);

        **builder.OwnsOne(x => x.Profile, profile =>
        {
            profile.Property(c => c.Value)
            .IsRequired()
            .HasColumnName("ProfileId")
            .HasColumnType("integer");
        });**
     }
 }


public class ProfileEnum
{
    public static ProfileEnum CompanyAdmin = new ProfileEnum(1, "CompanyAdmin");
    public static ProfileEnum Admin { get; } = new ProfileEnum(2, "Admin");
    public static ProfileEnum PowerUser { get; } = new ProfileEnum(3, "PowerUser");
    public static ProfileEnum Standard { get; } = new ProfileEnum(4, "Standard");
    private ProfileEnum(int val, string name)
    {
        Value = val;
        Name = name;
    }
}

我最终在实体映射内部配置了 .ignore(p => p.Name),问题消失了

public void Configure(EntityTypeBuilder<User> builder)
{
    builder.HasKey(x => x.UserId);

    builder.Property(x => x.Name)
        .HasMaxLength(200);

    builder.Property(x => x.DocumentNumber)
        .HasMaxLength(50);

    builder.OwnsOne(x => x.Profile, profile =>
    {
        profile.Property(c => c.Value)
        .IsRequired()
        .HasColumnName("ProfileId")
        .HasColumnType("integer");

        profile.Ignore(p => p.Name);
    });
 }