Use string type mapping when sending null values for JSON column update on SQL Server#38426
Open
Copilot wants to merge 5 commits into
Open
Use string type mapping when sending null values for JSON column update on SQL Server#38426Copilot wants to merge 5 commits into
Copilot wants to merge 5 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix JSON column update failure for date-related fields
Fix JSON column update failure for nullable date/time fields set to null on SQL Server
Jun 13, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes a SQL Server-specific failure when updating JSON-mapped owned properties to null for date/time CLR types (e.g., DateTime?, DateOnly?). The failure was caused by sending a NULL parameter with an underlying SQL type (e.g., date) that JSON_MODIFY rejects, even when the value is NULL.
Changes:
- Adjust SQL Server JSON single-property update parameter type mapping when the value is
null, falling back tonvarchar(max)for types not accepted byJSON_MODIFY. - Extend the shared JSON “all types” owned model with
TestNullableDateTimeandTestNullableDateOnly, including seeding and assertions. - Add/update provider functional tests and SQL baselines for nulling these JSON properties (SqlServer, SqlServer json-type fixture, Sqlite).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommand.cs | Changes null-parameter type mapping for JSON single-property updates to avoid JSON_MODIFY type rejection. |
| test/EFCore.Relational.Specification.Tests/Update/JsonUpdateTestBase.cs | Adds new base tests for setting nullable date/time JSON properties to null. |
| test/EFCore.SqlServer.FunctionalTests/Update/JsonUpdateSqlServerTest.cs | Adds SQL Server baselines for the new nulling tests and updates affected baselines. |
| test/EFCore.SqlServer.FunctionalTests/Update/JsonUpdateJsonTypeSqlServerTest.cs | Adds SQL Server (json-type fixture) baselines for the new nulling tests and updates affected baselines. |
| test/EFCore.Sqlite.FunctionalTests/Update/JsonUpdateSqliteTest.cs | Adds SQLite baselines for the new nulling tests and updates affected baselines. |
| test/EFCore.Specification.Tests/TestModels/JsonQuery/JsonOwnedAllTypes.cs | Adds nullable DateTime/DateOnly properties to the JSON owned type model. |
| test/EFCore.Specification.Tests/TestModels/JsonQuery/JsonQueryData.cs | Seeds values for the new nullable properties in the shared JSON all-types data. |
| test/EFCore.Specification.Tests/Query/JsonQueryFixtureBase.cs | Extends AssertAllTypes to include the new nullable date/time properties. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
On SQL Server, setting a nullable date/time property (
DateTime?,DateOnly?, etc.) inside a JSON-mapped owned entity tonullfailed withArgument data type date is invalid for argument 3 of json_modify function(SqlException 8116). EF emitted theJSON_MODIFYparameter using the property's nativedate/datetimetype mapping, whichJSON_MODIFYrejects — even when the value isnull.Changes
SqlServerModificationCommand.ProcessSinglePropertyJsonUpdate: when the value isnull, retain the property's type mapping only for typesJSON_MODIFYaccepts directly (string, bool, numeric); otherwise fall back tonvarchar(max)(SqlServerStringTypeMapping.UnicodeDefault). The rendered NULL parameter is independent of its declared type, so results are unchanged for the previously-working cases.Test model: added
TestNullableDateTime/TestNullableDateOnlyto the shared JSON all-types model, seed data, andAssertAllTypes.Tests: added
Edit_single_property_nullable_datetime_set_to_nullandEdit_single_property_nullable_dateonly_set_to_nulltoJsonUpdateTestBase, with provider SQL baselines for Sqlite, SQL Server, and the SQL Server JSON-type fixture. Updated the two full-document-serialization baselines affected by the new model properties.Notes
json_setaccepts null parameters of any type — so no provider change was needed there; tests confirm correct behavior.