Repository navigation
Conversation
maumar
force-pushed
the
fix32192
branch
2 times, most recently
from
March 14, 2025 01:19
ce9f999 to
12bbeb2
Compare
maumar
commented
Mar 14, 2025
| /// <summary> | ||
| /// A type representing CLR type of the JsonTypeMapping. | ||
| /// </summary> | ||
| public class JsonClrType |
Contributor
Author
There was a problem hiding this comment.
name suggestions are welcome @dotnet/efteam
Member
There was a problem hiding this comment.
Move it to .Storage and make the default constructor private.
My naming suggestion is JsonTypePlaceholder
Contributor
There was a problem hiding this comment.
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. |
maumar
commented
Mar 14, 2025
maumar
marked this pull request as ready for review
March 14, 2025 01:24
AndriySvyryd
approved these changes
Mar 14, 2025
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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