Passing JSON type as parameter to SQL Server 2016 stored procedure using ADO.Net in ASP.Net Core project

前端 未结 3 1213
梦谈多话
梦谈多话 2021-02-19 01:16

Can someone give example how to pass JSON type as parameter to SQL Server 2016 stored procedure using ADO.Net in C# ASP.Net Core Web Api project ? I want to see example of SQL

3条回答
  •  日久生厌
    2021-02-19 01:31

    SQL Server 2016 do have native JSON support - a new JSON datatype (which is based on nvarchar) is there, as well as a FOR JSON command to convert output from a query into JSON format

    Microsoft did not include a separate JSON datatype - instead, there are a number of JSON functions (to package up database rows into JSON, or to parse JSON into relational data) which operate on columns of type NVARCHAR(n)

    If you have JSON text, you can extract data from JSON or verify that JSON is properly formatted using built-in functions JSON_VALUE, JSON_QUERY, and ISJSON. For more advanced querying and analysis, the OPENJSON function can transform an array of JSON objects into a set of rows. Any SQL query can be executed on the returned result set. Finally, there is the FOR JSON clause that enables you to format query results as JSON text.

    So, I recommend you use NVARCHAR(MAX) as your stored procedure parameter.

提交回复
热议问题