-
Notifications
You must be signed in to change notification settings - Fork 228
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
Mapping issues with schema-scoped enums #930
Comments
The same thing is happening on |
@austindrenski any chance you can look at this, as you handled the original issue and PR? |
Just tested with Preview 8, the issue is not addressed yet. |
Confirmed that this is still an issue in 3.1. |
(Finally) took a deep look at this... tl;dr the full enum name (including schema) must be specified in the call to NpgsqlConnection.GlobalTypeMapper.MapEnum, so that it corresponds to the actual enum created by EF Core. This must be done whenever the enum is in a custom schema (i.e. not For more detail... enum support involves two layers working together - the Npgsql ADO driver and the EF Core provider. NpgsqlConnection.GlobalTypeMapper.MapEnum creates the mapping at the ADO level, and the EF Core provider pulls in those mappings for use in its own internal type mapper. EF Core's default schema settings affect what happens in migrations (this is why the CREATE TYPE AS ENUM is correct), but does not affect the type name as returned by the type mapping source - only the ADO-level mapping can do that at present. This, by the way, affects not only enum types appearing in migrations (e.g. in CREATE TABLE), but also in queries (e.g. if you try to cast to an enum). Passing the fully-qualified name to MapEnum ensures that the ADO layer has the correct name, and that flows into the EF Core provider's type mapping source, for integration in all SQL generated by the provider. This is a somewhat unfortunate/complicated situation, though it does work - #1026 tracks improving general enum mapping support. I've added a note in the EF enum doc page to make this clear. |
According to what I have read, the original issue #554 has been addressed by the pull request #605. But it seems that this issue still exists in the latest preview (3.0.0-preview5).
Here is the model and configuration:
The script generated by
dotnet ef migrations script
is:The expected script to create the my."Blogs" table is:
And
dotnet ef database update
will fail with this message:I have attached the project so that you can examine this issue.
ConsoleApp.zip
The text was updated successfully, but these errors were encountered: