-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix to #32192 - Remove lookup of JsonTypeMapping via JsonElement #35788
Conversation
ce9f999
to
12bbeb2
Compare
/// <summary> | ||
/// A type representing CLR type of the JsonTypeMapping. | ||
/// </summary> | ||
public class JsonClrType |
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.
name suggestions are welcome @dotnet/efteam
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.
Move it to .Storage
and make the default constructor private.
My naming suggestion is JsonTypePlaceholder
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.
Pull Request Overview
This PR fixes issues with JSON type mapping by introducing a new dummy CLR type (JsonClrType) to replace usage of JsonElement in EFCore, preventing misleading exceptions on providers that don’t support weak-typed JSON.
- Introduces the JsonClrType dummy marker type.
- Updates various Relational, SqlServer, and Sqlite mapping files to use JsonClrType instead of JsonElement.
- Updates tests and scaffolding baselines accordingly.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/EFCore.Relational/Metadata/JsonClrType.cs | New type definition for JsonClrType as a CLR marker. |
test/EFCore.Relational.Specification.Tests/Query/AdHocMiscellaneousQueryRelationalTestBase.cs | Added test to ensure a meaningful exception is thrown for a JsonElement property. |
src/EFCore.Relational/Metadata/Internal/JsonColumnBase.cs | Changed default type mapping lookup from JsonElement to JsonClrType. |
src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs | Modified type check for JSON mapping to use JsonClrType. |
src/EFCore.Relational/Storage/JsonTypeMapping.cs | Updated comments and mapping references from JsonElement to a generic description. |
src/EFCore.Relational/Metadata/Internal/JsonViewColumn.cs | Adjusted default store type mapping to use JsonClrType. |
src/EFCore.Relational/Metadata/Internal/JsonColumn.cs | Replaced JsonElement with JsonClrType in default mapping lookup. |
src/EFCore.Sqlite.Core/Storage/Internal/SqliteJsonTypeMapping.cs | Changed constructor parameter and mapping type to JsonClrType. |
src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs | Updated mapping dictionary entry from JsonElement to JsonClrType. |
src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs | Adjusted base constructor call to use JsonClrType. |
test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextModelBuilder.cs | Updated generic column accessors to reference JsonClrType. |
src/EFCore.Relational/Metadata/Internal/RelationalModel.cs | Changed lookup in relation to JSON column type mapping to use JsonClrType. |
test/EFCore.Sqlite.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextModelBuilder.cs | Updated generic column accessors to reference JsonClrType. |
...te.FunctionalTests/Scaffolding/Baselines/BigModel_with_JSON_columns/DbContextModelBuilder.cs
Show resolved
Hide resolved
When adding support for JSON mapped types, we decided to use JsonElement as a CLR type marker for JsonTypeMapping. This decision was in hindsight incorrect, it makes it hard for providers that actually support weak-typed json (npgsql) and throws cryptic exception (No coercion operator is defined between types 'System.IO.MemoryStream' and 'System.Text.Json.JsonElement) for providers that don't support it, when customers try to do it regardless. Fix is to create a dummy type and use that instead, so JsonElement is no longer recognized by base EFCore. Fixes #32192 also fixes #34752
When adding support for JSON mapped types, we decided to use JsonElement as a CLR type marker for JsonTypeMapping. This decision was in hindsight incorrect, it makes it hard for providers that actually support weak-typed json (npgsql) and throws cryptic exception (No coercion operator is defined between types 'System.IO.MemoryStream' and 'System.Text.Json.JsonElement) for providers that don't support it, when customers try to do it regardless. Fix is to create a dummy type and use that instead, so JsonElement is no longer recognized by base EFCore.
Fixes #32192
also fixes #34752