Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zotanmew opened this issue Nov 19, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working
Milestone

Comments

@zotanmew
Copy link

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.

@roji roji added this to the 9.0.2 milestone Nov 19, 2024
@roji roji added the bug Something isn't working label Nov 19, 2024
@roji roji self-assigned this Nov 19, 2024
@roji roji modified the milestones: 9.0.2, 9.0.3 Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants