Fix MapStringEnumAsPostgresEnum re-probing entities via modelBuilder.Entity#2
Merged
dmytro-khmara merged 1 commit intomasterfrom Apr 27, 2026
Merged
Conversation
…Entity The walker called modelBuilder.Entity(entityType.ClrType) on each entity to set the column type on string-enum properties. That re-enters EF's entity-discovery conventions, which probe every CLR property on the type (and on reference-typed nested types they pull in). On EF Core 10 models with a complex-collection element exposing e.g. Dictionary<K, V> with a user-supplied HasConversion, the probing fires before the user's fluent config has been applied — and EF throws "Unable to determine the relationship represented by navigation ...", breaking design-time DbContext construction (migrations, scaffolding). Mutate IMutableProperty directly via SetColumnType instead. Walks only existing model state; no convention re-entry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
MapStringEnumAsPostgresEnum<TEnum>()calledmodelBuilder.Entity(entityType.ClrType)on every entity to set the column type on its string-enum properties. That re-enters EF's entity-discovery conventions, which probe every CLR property on the type (and on any reference-typed nested types they pull in).Dictionary<K, V>configured viaHasConversion(...), the probing fires before the user's fluent config has been applied. EF then throwsUnable to determine the relationship represented by navigation '<element>.<property>' of type 'Dictionary<int, long>', breaking design-timeDbContextconstruction (migrations, scaffolding).IMutableProperty.SetColumnType(...)directly. Walks only existing model state; no convention re-entry. The per-propertyHasPostgresStringEnum<TEnum>()overload was already unaffected (it didn't go through the walker).Repro
A new unit test,
MapStringEnumAsPostgresEnum_DoesNotProbeCustomConvertedComplexCollectionProperties, configures aTournamententity with a JSON-mappedSchedulecomplex property containing aComplexCollection<Stage>whoseSplits(Dictionary<int, long>) is round-tripped via aValueConverter. Without the fix the test fails with the exact consumer error; with it, all 24 unit tests pass.Test plan
dotnet test ./test/StrEnum.Npgsql.EntityFrameworkCore.UnitTests— 24/24 pass on the fix branchUnable to determine the relationship represented by navigation 'Stage.Splits' of type 'Dictionary<int, long>') and passes after the fix