Skip to content

Fix several small issues in the compiled model#38441

Merged
AndriySvyryd merged 3 commits into
mainfrom
Issue35142
Jun 18, 2026
Merged

Fix several small issues in the compiled model#38441
AndriySvyryd merged 3 commits into
mainfrom
Issue35142

Conversation

@AndriySvyryd

@AndriySvyryd AndriySvyryd commented Jun 17, 2026

Copy link
Copy Markdown
Member

Handle discriminators that use a value converter in the compiled model
Handle negative discriminators values in the compiled model Handle global namespaces in the compiled model
Avoid variable-name clashes in lambdas in the compiled model
Match UnsafeAccessors accessibility to the target type

Fixes #37259, #35142, #35142, #35011, #35013

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes several edge cases in compiled model and design-time code generation, focused on making generated code compile and behave correctly when discriminators use converters, enum values are negative/unnamed, types are in the global namespace, and when generated identifiers/access modifiers would otherwise cause compilation errors.

Changes:

  • Emit discriminator values via provider values when a discriminator has a value converter, and add runtime support to materialize the CLR discriminator value from the provider value.
  • Improve C# literal generation for unnamed/negative enum values and add tests covering these cases.
  • Avoid generated-code conflicts by uniquifying lambda parameter names against constant replacements, avoid emitting empty using ; for global-namespace types, and match generated unsafe accessor/entity-type class accessibility to the target CLR type.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/No_NativeAOT/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DependentDerivedEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/BigModel/DependentBaseEntityType.cs Baseline update to set discriminator via provider value.
test/EFCore.Design.Tests/Query/LinqToCSharpSyntaxTranslatorTest.cs Adds tests ensuring lambda parameters are uniquified vs constant replacements.
test/EFCore.Design.Tests/Migrations/Design/GlobalNamespaceColumnType.cs New global-namespace enum used to validate migrations using generation.
test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs Adds regression test preventing using ; for global-namespace types.
test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs Adds tests for unnamed/negative enum literal emission.
src/Shared/SharedTypeExtensions.cs Avoids returning empty namespaces when collecting type namespaces.
src/EFCore/Metadata/RuntimeTypeBase.cs Adds provider-value-based discriminator support with lazy conversion.
src/EFCore/EFCore.baseline.json Updates API baseline for new internal-facing method.
src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs Emits discriminator provider values when converters exist; aligns accessibility modifiers.
src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs Tracks constant replacement identifiers to avoid lambda parameter name clashes.
src/EFCore.Design/Design/Internal/CSharpHelper.cs Fixes enum literal generation for unnamed/negative values.

Comment thread src/EFCore/Metadata/RuntimeTypeBase.cs
Handle negative discriminators values in the compiled model
Handle global namespaces in the compiled model
Avoid variable-name clashes in lambdas in the compiled model
Match UnsafeAccessors accessibility to the target type

Fixes #37259, #35142, #35142, #35011, #35013
@AndriySvyryd AndriySvyryd marked this pull request as ready for review June 17, 2026 19:50
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner June 17, 2026 19:50
Copilot AI review requested due to automatic review settings June 17, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Comment thread src/EFCore/Metadata/RuntimeTypeBase.cs
Comment thread src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs
Comment thread test/EFCore.Design.Tests/Migrations/Design/GlobalNamespaceColumnType.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AndriySvyryd AndriySvyryd requested a review from cincuranet June 17, 2026 20:01
Copilot AI review requested due to automatic review settings June 18, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Comment thread src/EFCore/Metadata/RuntimeTypeBase.cs
Comment thread src/EFCore/Metadata/RuntimeTypeBase.cs
@AndriySvyryd AndriySvyryd merged commit 1a62dde into main Jun 18, 2026
15 checks passed
@AndriySvyryd AndriySvyryd deleted the Issue35142 branch June 18, 2026 16:37
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.

Compiled Model fails when discriminator uses non-primitive type (SmartEnum); cannot scaffold C# literals

3 participants