dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.04k stars 4.68k forks source link

Expose Json in SqlDbType #103925

Closed saurabh500 closed 2 months ago

saurabh500 commented 3 months ago

Background and motivation

The System.Data.SqlDbType enum represents the datatypes supported by SQL Server and is used with SqlParameter to specify the column type to be used in SQL server operations while execution SqlCommand.

With the JSON datatype being supported in SQL Server link There is a need to support the JSON type in Microsoft.Data.SqlClient ADO.Net provider for SQL Server.

The API suggestion is aimed at adding an enum called Json with value 35 in SqlDbType. Once this enum is available Microsoft.Data.SqlClient (the SQL Server driver) can then leverage the enum value to allow JSON operations using Microsoft.Data.SqlClient APIs.


namespace System.Data
{
    // Specifies the SQL Server data type.
    public enum SqlDbType
    {
        Json = 35,
    }
}

The version of Microsoft.Data.SqlClient targeting .Net 9, will be able to use the enum SqlDbType.Json to provide JSON support.

API Proposal


namespace System.Data
{
    // Specifies the SQL Server data type.
    public enum SqlDbType
    {
        Json = 35,
    }
}

API Usage

using Microsoft.Data.SqlClient;

SqlParameter param = new SqlParameter();

param.SqlDbType = System.Data.SqlDbType.Json;

There are parameters / properties in the constructors and APIs, which will be enhanced to support SqlDbType.Json

SqlParameter SqlParameterCollection SqlMetaData

Alternative Designs

No response

Risks

No response

dotnet-policy-service[bot] commented 3 months ago

Tagging subscribers to this area: @davoudeshtehari, @david-engel, @jrahnama See info in area-owners.md if you want to be subscribed.

saurabh500 commented 3 months ago

cc @roji @uc-msft @David-Engel @apoorvdeshmukh @deepaksa1 @cheenamalhotra

roji commented 3 months ago

Thanks. Just noting that SqlDbType isn't actually referenced anywhere inside the runtime libraries, and @saurabh500 confirmed that previous versions of SqlClient are confirmed to throw on unknown SqlDbType values, so if a user attempts to use the new SqlDbType.Json with an older SqlClient, we should be safe there.

bartonjs commented 2 months ago

Video

Looks good as proposed


namespace System.Data
{
    // Specifies the SQL Server data type.
    public enum SqlDbType
    {
        Json = 35,
    }
}