Repository navigation
Keep unnamed bits when generating [Flags] enum literals in CSharpHelper - #39381
Merged
AndriySvyryd merged 1 commit intoOct 22, 2026
Merged
AndriySvyryd merged 1 commit into
AndriySvyryd merged 1 commit into
Conversation
A flags value with bits that have no named member (e.g. (E)5 where only One = 1 is named) was generated as E.One, silently dropping the remaining bits in migrations, snapshots and compiled models.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes address the reported data-loss issue and include regression coverage.
No open issues 🎉
What changed in this PR
This pull request updates CSharpHelper to preserve unnamed bits when generating literals for [Flags] enum values, preventing data loss in migrations, snapshots, and compiled models.
Changes:
- Emits unnamed flag bits as an explicit enum cast.
- Handles fully named, fully unnamed, and partially unnamed flag values.
- Adds regression test coverage for these scenarios.
| File | Description |
|---|---|
test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs |
Adds regression tests for flags values containing unnamed bits. |
src/EFCore.Design/Design/Internal/CSharpHelper.cs |
Preserves unnamed bits in generated flags enum expressions. |
Review effort: Lite
AndriySvyryd
approved these changes
Oct 22, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
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.
A flags value with bits that have no named member (e.g. (E)5 where only One = 1 is named) was generated as E.One, silently dropping the remaining bits in migrations, snapshots and compiled models.