Skip to content

Omit unsupported collations from complex-collection snapshots - #39481

Open
AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-usecollation-issue
Open

AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-usecollation-issue

Conversation

Copilot AI commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

A global string UseCollation() convention causes snapshots to emit unsupported calls on JSON-mapped complex-collection properties, making the generated C# uncompilable.

  • Snapshot generation: Filter collation annotations from complex-collection properties before generating fluent API calls. Preserve collations on ordinary properties.
  • Regression coverage: Cover the global convention and nested complex collections, including compilation of generated snapshots.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix global UseCollation() convention for ComplexCollection properties Omit unsupported collations from complex-collection snapshots Oct 30, 2026
Copilot AI requested a review from AndriySvyryd October 30, 2026 22:59
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot October 30, 2026 23:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate-severity finding remains: the snapshot collation filter also drops collations on primitive collections inside complex collections, even though those builders support collation and only regular properties should be filtered.

3 open issues
What changed in this PR

This PR fixes a bug where a global UseCollation() convention made the generated model snapshot contain calls that do not compile on JSON-mapped complex collections. The snapshot generator now drops collation for complex-collection properties. Regular properties keep their collation. The PR adds a regression test that builds the generated snapshot and checks the collations that are kept and dropped.

Changes:

  • The snapshot generator removes the collation annotation for properties declared in a complex collection.
  • A new test covers the global convention on a complex collection and checks that the generated snapshot compiles and keeps collations on ordinary properties.
  • An existing test now sets and checks a collation on a complex-collection property, so the omission is covered there too.
File Description
test/​EFCore.Design.Tests/​Migrations/​Design/​CSharpMigrationsGeneratorTest.ModelSnapshot.cs Adds a regression test for global collations on complex collections and extends an existing test to check that collations are omitted.
src/​EFCore.Design/​Migrations/​Design/​CSharpSnapshotGenerator.cs Removes the collation annotation for complex-collection properties so the generated snapshot compiles.

Review effort: Lite

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 30, 2026 23:25
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 30, 2026 23:25
@AndriySvyryd
AndriySvyryd requested review from cincuranet and a lite review from Copilot October 30, 2026 23:25
@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 30, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new collation filter in the snapshot generator also drops collations from primitive collections inside complex collections, which support them, so those collations would be silently lost from the snapshot and no test covers that path.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Add snapshot test for collated primitive collections

test/​EFCore.Design.Tests/​Migrations/​Design/​CSharpMigrationsGeneratorTest.ModelSnapshot.cs:6816

The new test only covers a regular string property, so it misses the primitive-collection path changed in src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs:482-485. Primitive collections inside a complex collection support UseCollation, so the new filter can drop their collation from snapshots and no test fails. Add a test that sets a collation on a primitive collection inside a complex collection and asserts it survives the snapshot round-trip.

3 resolved since last review

Review effort: Lite

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main ed0b576 copilot/fix-global-u... 4caa4da +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main ed0b576 copilot/fix-global-u... 4caa4da +/-
src/Shared/NonC...yInitializer.cs 12% 11% -1%
src/EFCore.Rela...alConnection.cs 93% 93% 0%
src/EFCore.Desi...hotGenerator.cs 99% 99% 0%
src/EFCore.Cosm...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...erExtensions.cs 46% 46% 0%
src/EFCore.Cosm...peExtensions.cs 73% 73% 0%
src/EFCore.Cosm...StreamHelper.cs 87% 87% 0%
src/EFCore.Cosm...delValidator.cs 98% 98% 0%
src/EFCore.Cosm...orConvention.cs 94% 94% 0%
src/Microsoft.D...nnectionPool.cs 97% 100% +3%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

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.

Global UseCollation() convention generates uncompilable model snapshot for JSON-mapped ComplexCollection properties

3 participants