Skip to content

BulkInsertOrUpdateAsync fails for nullable JSON type fields in SQL Server #1919

@TheSpookyElectric

Description

@TheSpookyElectric

EFCore.BulkExtensions 10.0.0
SQL Server 2025 & Azure SQL Server

Note: This is not new behavior in 10.0.0. I've seen the same issue in previous versions.


When using the native JSON type (https://learn.microsoft.com/en-us/sql/t-sql/data-types/json-data-type?view=sql-server-ver17)

Entity:

public class SomeEntity
{
   public String? SomeJSON { get; set; }
}

EF Core Entity Config:

modelBuilder.Entity<SomeEntity>(entity => 
{ 
   ...
   entity .Property(x=> x.SomeJSON)
      .HasColumnType("JSON");
   ...

in the database, the field will be type (json, null)

If you set NULL as the value, during a BulkInsertOrUpdateAsync, it will fail saying:

"The incoming tabular data stream (TDS) protocol stream is incorrect. The stream ended unexpectedly."

So far, the only way I've gotten around it was to use "{}" as the value since that's a valid JSON document.

According to the documentation (link above), the following are all valid:

DECLARE @null JSON = NULL -- valid
DECLARE @object JSON = '{}' -- valid
DECLARE @array JSON = '[]' -- valid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions