Skip to content

FluentAPI configuration PrimitiveCollection on OwnedNavigationBuilder returns PropertyBuilder instead of PrimitiveCollectionBuilder #32601

@MJLHThomassenHadrian

Description

@MJLHThomassenHadrian

When configuring an owned type, if that owned type has a primitive collection, configuring it using the new PrimitiveCollection on the builder does not alow me to specify .ElementType() because a PropertyBuilder is returned instead of a PrimitiveCollectionBuilder. I need this to convert a list of enums to strings (instead of having the enums as numbers in the database).

Include your code

Simplified example.

Entity definition:

public class Foo
{
    public Guid Id { get; set; }
    public OwnedBar Bar { get; set; }
}

public class OwnedBar
{
    public List<SomeEnum> MyPrimitiveCollection { get; set; }
}

Configuration:

public class FooConfiguration : IEntityTypeConfiguration<Foo>
{
    public void Configure(EntityTypeBuilder<Foo> builder)
    {
        builder.HasKey(x => x.Id);

        builder.OwnsOne(x => x.Bar)
            .PrimitiveCollection(x => x.MyPrimitiveCollection)
            .ElementType() // <-- This is missing
            .HasConversion<string>();
    }
}

Include provider and version information

EF Core version: 8.0.0
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 8.0
Operating system: Windows 11
IDE: VS Code

Update 2023-12-20: Included information that the list is an list of enum members instead of ints.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions