Add StrEnum.Npgsql.EntityFrameworkCore package#1
Merged
dmytro-khmara merged 1 commit intomasterfrom Apr 27, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
StrEnum.Npgsql.EntityFrameworkCore— the EF Core wrapper aroundStrEnum.Npgsql2.0. Maps StrEnum string enums to native Postgres enum types in EF Core models, migrations, and queries.The split mirrors how the Npgsql ecosystem itself separates the ADO.NET driver from EF Core integration: raw-Npgsql consumers use
StrEnum.Npgsqldirectly; EF Core consumers install this package on top.What's in here
Public API (src/StrEnum.Npgsql.EntityFrameworkCore/):
DbContextOptionsBuilderExtensions.UseStringEnums()— installs theIValueConverterSelectorthat recognisesStringEnum<T>properties as scalars (text-mode storage).DbContextOptionsBuilderExtensions.UseStringEnumsAsPostgresEnums()— installs the new relational-type-mapping plugin so EF Core bindsStringEnum<T>properties to native Postgres enum columns on the wire.ModelBuilderExtensions.HasPostgresStringEnum<T>(name?, schema?)— declares the PG enum in the model (produces theCREATE TYPEmigration).ModelBuilderExtensions.MapStringEnumAsPostgresEnum<T>(name?, schema?)— declares the PG enum and configures the column type for every matching property.PropertyBuilderExtensions.HasPostgresStringEnum<T>(name?, schema?)— per-property column-type configuration. Schema is inherited from the model-level call when omitted.Internals (src/StrEnum.Npgsql.EntityFrameworkCore/Internal/):
NpgsqlStringEnumTypeMapping<T>—RelationalTypeMappingwhoseConfigureParameterpinsNpgsqlParameter.DataTypeNameto the PG enum name, so Npgsql'sMapStringEnum<T>resolver picks up the parameter rather than EF defaulting toNpgsqlDbType.Text(the missing piece that produced42804: column is of type my_enum but expression is of type textend-to-end).NpgsqlStringEnumTypeMappingSourcePlugin—IRelationalTypeMappingSourcePluginreturning the mapping for anyStringEnum<T>property with an explicit store type.StrEnumNpgsqlOptionsExtension—IDbContextOptionsExtensionwiring the plugin into EF Core's service collection viaUseStringEnumsAsPostgresEnums().Tests:
FindMappingshape.StringEnum<T>properties through EF Core against a real Postgres — both default and schema-qualified PG enum types. These also serve as the proof thatUseStringEnumsAsPostgresEnums()closes the wire-binding gap that the previous resolver-only attempt couldn't reach from inside EF Core.CI: mirrors the structure used by
StrEnum.Npgsql— Docker-based unit-test job plus a separateintegration-testsjob using Docker on the GitHub runner for Testcontainers.Test plan
dotnet test— 23 unit + 2 integration pass on net10.0StrEnum.Npgsql2.0.0 (just published) viaPackageReference, not a relativeProjectReferenceWHERE x = T.Valuepredicate)