Background:
As part of enhancing support in SqlClient for JSON datatype for Sql Server as mentioned in #2622, SqlDbType needed to be enhanced with enum called Json and introduction of a SqlType class for JSON type was needed.
An enum called Json with value 35 in SqlDbType was recently added in the runtime repo through issue #103925
The next follow up item is to provide a SqlType class to work with the JSON data. This proposal talks about the design of SqlJson class which aims to represent the JSON data stored in or retrieved from a server.
API Proposal
using System;
using System.Data.SqlTypes;
using System.Text.Json;
namespace Microsoft.Data.SqlTypes
{
/// <summary>
/// Represents the Json Data type in SQL Server.
/// </summary>
public class SqlJson : INullable
{
/// <summary>
/// Parameterless constructor. Initializes a new instance of the SqlJson class which
/// represents a null JSON value.
/// </summary>
public SqlJson() { }
/// <summary>
/// Takes a <see cref="string"/> as input and initializes a new instance of the SqlJson class.
/// </summary>
/// <param name="jsonString"></param>
public SqlJson(string jsonString) { }
/// <summary>
/// Takes a <see cref="JsonDocument"/> as input and initializes a new instance of the SqlJson class.
/// </summary>
/// <param name="jsonDoc"></param>
public SqlJson(JsonDocument jsonDoc) { }
/// <inheritdoc/>
public bool IsNull => throw null;
/// <summary>
/// Represents a null instance of the <see cref="SqlJson"/> type.
/// </summary>
public static SqlJson Null { get { throw null; } }
/// <summary>
/// Gets the string representation of the Json content of this <see cref="SqlJson" /> instance.
/// </summary>
public string Value { get ; }
}
}
Additionally, SqlDataReader will be enhanced with addition of API for returning SqlJson type
/// <summary>
/// Gets the value of the specified column as JSON value.
/// </summary>
virtual public SqlJson GetSqlJson(int i)
Background:
As part of enhancing support in SqlClient for JSON datatype for Sql Server as mentioned in #2622, SqlDbType needed to be enhanced with enum called
Jsonand introduction of aSqlTypeclass for JSON type was needed.An enum called
Jsonwith value35inSqlDbTypewas recently added in the runtime repo through issue #103925The next follow up item is to provide a
SqlTypeclass to work with the JSON data. This proposal talks about the design ofSqlJsonclass which aims to represent the JSON data stored in or retrieved from a server.API Proposal
Additionally, SqlDataReader will be enhanced with addition of API for returning
SqlJsontype