Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

Fixes #37143

Description
When a discriminator property has a non-string type (e.g., int) and uses the default property name "Discriminator", the model snapshot generator would omit the type argument. This caused the discriminator type to default to string when reading the snapshot back, resulting in spurious migrations being generated on every scaffold.

// Before (loses type info, defaults to string on read-back)
b.HasDiscriminator().HasValue(0);

// After (preserves int type)
b.HasDiscriminator<int>("Discriminator").HasValue(0);

Customer impact
Customers using non-string discriminator types with the default "Discriminator" property name would see new migrations generated each time they ran dotnet ef migrations add, even when no actual model changes were made.
A workaround is to fix the snapshot manually, but this would need to be performed after every new migration. Another workaround is to use a custom discriminator property name.

How found
Customer reported on 10.0.0.

Regression
Yes, from EF Core 9.0. Introduced in #35744

Testing
Test added

Risk
Low. The change is minimal, only affects snapshot generation output, which is a design-time action

Original prompt

Fix #37143 by always generating a HasDiscriminator call with generic type argument and property name in the snapshot.


💡 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.

Copilot AI changed the title [WIP] Fix snapshot to always generate HasDiscriminator call Fix #37143: Always generate HasDiscriminator with type argument and property name in snapshot Nov 26, 2025
Copilot finished work on behalf of AndriySvyryd November 26, 2025 02:04
Copilot AI requested a review from AndriySvyryd November 26, 2025 02:04
@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 Nov 27, 2025

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

...

Updated the PR description using the requested template.

Copilot finished work on behalf of AndriySvyryd November 27, 2025 00:24
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-hasdiscriminator-call-snapshot branch from e53830c to ed302cc Compare November 27, 2025 00:35
@AndriySvyryd AndriySvyryd marked this pull request as ready for review November 27, 2025 00:45
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner November 27, 2025 00:45
@AndriySvyryd AndriySvyryd changed the title Fix #37143: Always generate HasDiscriminator with type argument and property name in snapshot [release/10.0] Always generate HasDiscriminator with type argument and property name in snapshot Dec 2, 2025
@AndriySvyryd AndriySvyryd requested a review from artl93 December 2, 2025 18:58
@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 regression.

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