Skip to content

NpgsqlDbContextOptionsBuilder.MapEnum<T> doesn't respect PgNameAttribute #3379

Description

@zotanmew

As discussed in #3178, here's a minimal repro (untested, but using the same patterns as our big application, if it doesn't work I'll create a full repo and link it here):

builder.Services.AddNpgsql<DatabaseContext>("<connectionString>", opts =>
{
opts.ConfigureDataSource(dataSource => { dataSource.MapEnum<Example.ExampleEnum>(); });
opts.MapEnum<Example.ExampleEnum>();
});

alongside

class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options)
{
public virtual DbSet<Example> Examples { get; init; } = null!;
}
public class Example
{
[PgName("example_enum")]
public enum ExampleEnum
{
Test,
OtherTest
}
public ExampleEnum ExampleValue { get; set; }
}

When used in a query, causes an exception containing MessageText: type "example" does not exist.

When leaving out either of the MapEnum<T> calls, an InvalidCastException is thrown on query.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions