-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[release/10.0] Fix snapshot generation to capture column type for JSON columns #37284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/10.0] Fix snapshot generation to capture column type for JSON columns #37284
Conversation
Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs
Show resolved
Hide resolved
test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs
Outdated
Show resolved
Hide resolved
- Modified AnnotationCodeGenerator to generate column type for owned
and complex types mapped to JSON even when not explicitly set
- Updated Owned_types_mapped_to_json_are_stored_in_snapshot to expect
HasColumnType("nvarchar(max)") and verify via GetContainerColumnType()
- Renamed Complex_types_mapped_to_json_are_stored_in_snapshot to
Complex_types_mapped_to_json_with_explicit_column_type_are_stored_in_snapshot
- Added new Complex_types_mapped_to_json_are_stored_in_snapshot test
without explicit column type expecting nvarchar(max) in snapshot
Fixes #37275
Co-authored-by: AndriySvyryd <[email protected]>
… type test Addresses PR feedback to not add a custom type for the test. Co-authored-by: AndriySvyryd <[email protected]>
Moved the logic for adding ContainerColumnType annotation from AnnotationCodeGenerator to CSharpSnapshotGenerator as requested. Now GenerateEntityTypeAnnotations and GenerateComplexPropertyAnnotations check if the entity/complex type is mapped to JSON and add the ContainerColumnType annotation if it's missing. Co-authored-by: AndriySvyryd <[email protected]>
Per review feedback, updated CSharpSnapshotGenerator to first try GetContainerColumnType() for both entity types and complex types, then fall back to type mapping source if the method returns null. Co-authored-by: AndriySvyryd <[email protected]>
|
@copilot Add |
…older snapshots - Created SqlServerSnapshotModelProcessor that detects snapshots from version 9 or older - Processor sets ContainerColumnType to nvarchar(max) for JSON owned types without the annotation - Registered the processor in SqlServerDesignTimeServices using TryAddProviderSpecificServices - Added EFCore.Design project reference to EFCore.SqlServer for design-time types - Added test to verify the processor correctly handles version 9 snapshots Co-authored-by: AndriySvyryd <[email protected]>
Fixed in efc876a. Added |
|
@copilot Revert the last commit |
Reverted the last commit that added: - SqlServerSnapshotModelProcessor class - EFCore.Design project reference in EFCore.SqlServer - Related test Co-authored-by: AndriySvyryd <[email protected]>
… of #37284 without complex types) Co-authored-by: AndriySvyryd <[email protected]>
|
cc @artl93 |
|
@AndriySvyryd - would it make sense to wait for the full fix? |
|
Never mind - I see we're ready to take both. |
artl93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regression, customer reported, blocked. Approved. Please take at same time as #37294.
Port of #37284 Co-authored-by: AndriySvyryd <[email protected]>
Fixes #37275
Description
EF Core 10 added support for
jsonSQL Server type for JSON column and it's used by default if the target SQL Server version supports it, but no migrations to convert the columns to the newjsoncolumn type are created because the model snapshot doesn't capture the default store type for JSON columns.For the complete fix #37294 is required for the user to create a migration in 9 that has the explicit type.
Customer impact
Customers upgrading from EF Core 9 to 10 who use
ToJson()won't get migrations generated to update the column type fromnvarchar(max)tojson. The workaround is to manually specify.HasColumnType("json")on the JSON column.How found
Customer reported on EF 10.0.0
Regression
No, new feature.
Testing
Test added
Risk
Low. Targeted fix to include the default column type in the model snapshot. Only affects design-time.
💡 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.