Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Fixes #37256

Description
Snapshot generation for properties in complex collections produces uncompilable code because it emits fluent API calls (HasMaxLength, HasPrecision, IsConcurrencyToken, ValueGenerated*) that don't exist on ComplexCollectionTypePropertyBuilder.

// Convention applies MaxLength to all strings
configurationBuilder.Properties<string>().HaveMaxLength(255);

// Generated snapshot fails to compile:
b.ComplexCollection(..., b1 =>
{
    b1.Property<string>("Name")
        .HasMaxLength(255); // CS1061: 'ComplexCollectionTypePropertyBuilder' does not contain 'HasMaxLength'
});

Customer impact
Customers using bulk configuration of these facets for all properties get compilation errors in their generated migration snapshot files. The workaround is to manually remove the unsupported fluent API calls from the generated snapshot.

How found
Customer reported on EF 10. This is expected to affect a small part of developers using complex collections.

Regression
No. It only manifests when a new EF 10 feature is used.

Testing
Tests added.

Risk
Low. The targeted fix is to just avoid emitting invalid code for the affected scenarios.

Original prompt

Fix #37256 by changing snapshot generation to ignore the annotations for which there are no methods on the configuration API for properties on a complex collection


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@AndriySvyryd
Copy link
Member

@copilot Add a ModelDiffer test to check that no operations are generated when the model contains an annotation that's ignored in the snapshot

Skip generating HasMaxLength and HasPrecision annotations for properties
in complex collections since ComplexCollectionTypePropertyBuilder doesn't
support these methods. Also skip IsConcurrencyToken and ValueGenerated*
methods for the same reason.

Fixes #37256

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix snapshot generation to ignore irrelevant annotations Fix snapshot generation for complex collection properties Dec 1, 2025
Copilot AI requested a review from AndriySvyryd December 1, 2025 19:50
Add test to verify that no operations are generated when the model
contains annotations (like MaxLength) that are ignored in the snapshot
for complex collection properties.

Addresses review feedback from @AndriySvyryd

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot Add a ModelDiffer test to check that no operations are generated when the model contains an annotation that's ignored in the snapshot

Added Noop_on_complex_collection_property_annotations_not_in_snapshot test in commit 2aa95cc. The test sets MaxLength on a string property in a complex collection (simulating convention behavior) and verifies no migration operations are generated since this annotation is ignored in the snapshot.

- Remove method overloads with isInComplexCollection parameter
- Check property.DeclaringType directly to determine if in complex collection
- Update test to also configure IsConcurrencyToken, ValueGenerated, precision and scale
- Empty target lambda in ModelDiffer test as snapshot doesn't have extra config

Addresses review feedback from @AndriySvyryd

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI requested a review from AndriySvyryd December 2, 2025 00:15
@AndriySvyryd AndriySvyryd changed the title Fix snapshot generation for complex collection properties [release/10.0] Fix snapshot generation for complex collection properties Dec 2, 2025
@AndriySvyryd
Copy link
Member

@copilot Update progress by rewriting the PR summary using this template:

Fixes #{number}

**Description**
{Issue description}

**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}

**How found**
{Was it customer reported or found during verification? How many customers are affected?}

**Regression**
{Is it a regression from a released version? Which one?}

**Testing**
{How the changes were tested}

**Risk**
{Low/Medium/High, argument why}

Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot Update progress by rewriting the PR summary using this template:

...

Updated the PR description with the requested template format.

@AndriySvyryd AndriySvyryd marked this pull request as ready for review December 2, 2025 02:20
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner December 2, 2025 02:20
@AndriySvyryd AndriySvyryd requested a review from artl93 December 8, 2025 19:53
@AndriySvyryd
Copy link
Member

cc @artl93

Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Customer reported. New area. Limited scope with targeted fix. Approved.

@AndriySvyryd AndriySvyryd added this to the 10.0.2 milestone Dec 8, 2025
@AndriySvyryd AndriySvyryd merged commit ebb6756 into release/10.0 Dec 8, 2025
9 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-snapshot-generation-annotations branch December 8, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants