Fix HasDiscriminator with default name "Discriminator" failing for non-string types#37785
Draft
Fix HasDiscriminator with default name "Discriminator" failing for non-string types#37785
Conversation
…hanged Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issue with .HasDiscriminator in EF Core 10
Fix HasDiscriminator with default name "Discriminator" failing for non-string types
Feb 24, 2026
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.
When calling
.HasDiscriminator<TEnum>("Discriminator")using the default discriminator column name, EF Core 10 incorrectly throws during model validation because conventions override the user-configured type back tostring.Root cause
TypeBase.SetDiscriminatorPropertyhas an early return when the property name is unchanged (e.g., user specifies"Discriminator"and the convention-created default is also"Discriminator"). This early return skipped updating the annotation'sConfigurationSource, leaving it atConvention. When derived types were subsequently registered, conventions re-ran and, seeing aConvention-level annotation, successfully overrode the discriminator property type back tostring.Fix
TypeBase.SetDiscriminatorProperty: when taking the early return for an unchanged property name, also callUpdateConfigurationSourceon the existing annotation so the caller'sConfigurationSource(e.g.,Explicit) is properly propagated.Does_not_detect_missing_discriminator_values_when_using_default_discriminator_name_with_non_string_typetoModelValidatorTest.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.