Skip to content

Fix MapStringEnumAsPostgresEnum re-probing entities via modelBuilder.Entity#2

Merged
dmytro-khmara merged 1 commit intomasterfrom
fix-walker-complex-collection-probe
Apr 27, 2026
Merged

Fix MapStringEnumAsPostgresEnum re-probing entities via modelBuilder.Entity#2
dmytro-khmara merged 1 commit intomasterfrom
fix-walker-complex-collection-probe

Conversation

@dmytro-khmara
Copy link
Copy Markdown
Member

@dmytro-khmara dmytro-khmara commented Apr 27, 2026

Summary

  • MapStringEnumAsPostgresEnum<TEnum>() called modelBuilder.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).
  • On EF Core 10 models with a complex-collection element exposing e.g. Dictionary<K, V> configured via HasConversion(...), the probing fires before the user's fluent config has been applied. EF then throws Unable to determine the relationship represented by navigation '<element>.<property>' of type 'Dictionary<int, long>', breaking design-time DbContext construction (migrations, scaffolding).
  • Fix: mutate IMutableProperty.SetColumnType(...) directly. Walks only existing model state; no convention re-entry. The per-property HasPostgresStringEnum<TEnum>() overload was already unaffected (it didn't go through the walker).

Repro

A new unit test, MapStringEnumAsPostgresEnum_DoesNotProbeCustomConvertedComplexCollectionProperties, configures a Tournament entity with a JSON-mapped Schedule complex property containing a ComplexCollection<Stage> whose Splits (Dictionary<int, long>) is round-tripped via a ValueConverter. 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 branch
  • Verified the new repro test fails on master (Unable to determine the relationship represented by navigation 'Stage.Splits' of type 'Dictionary<int, long>') and passes after the fix
  • Smoke-test on the original consumer model that triggered the report

…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>
@dmytro-khmara dmytro-khmara merged commit eeb3fed into master Apr 27, 2026
2 checks passed
@dmytro-khmara dmytro-khmara deleted the fix-walker-complex-collection-probe branch April 27, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant