Fix enum discriminator serialization inconsistency in Cosmos provider#36771
Closed
Copilot wants to merge 2 commits intorelease/10.0from
Closed
Fix enum discriminator serialization inconsistency in Cosmos provider#36771Copilot wants to merge 2 commits intorelease/10.0from
Copilot wants to merge 2 commits intorelease/10.0from
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Discriminator on derived type is being incorrectly updated with integer value of enum (EF Core CosmosDB provider)
Fix enum discriminator serialization inconsistency in Cosmos provider
Sep 12, 2025
6 tasks
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.
The Cosmos provider was incorrectly serializing enum discriminators as integers during entity updates, even when configured with a string converter. This caused entities to become unqueryable after updates.
Problem
When using enum discriminators with string conversion in the Cosmos provider:
"ThingyTwo")1)This inconsistency broke queries that expected string discriminator values, making updated entities unloadable.
Root Cause
The issue was in
DocumentSource.ConvertPropertyValue()which usedentry.GetCurrentProviderValue(property)for all properties. During updates, change tracking could corrupt discriminator property values, causing the method to return the raw enum integer instead of the converted string value.Solution
Enhanced
ConvertPropertyValue()to handle discriminator properties specially:entry.EntityType.FindDiscriminatorProperty()entry.EntityType.GetDiscriminatorValue()This ensures discriminator values remain consistent regardless of change tracking state.
Fixes #34852.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.