Sql
SQL Server 2016 specific features
Assembly: ServiceStack.OrmLite.dll
View Source
public static class Sql : object
Fields
VARCHAR
View Source
public static string VARCHAR
EOT
View Source
public const string EOT = null
Methods
Flatten(IEnumerable)
View Source
public static List<object> Flatten(IEnumerable list)
Returns
List<System.Object>
Parameters
Type | Name |
---|---|
IEnumerable | list |
In<T, TItem>(T, TItem[])
View Source
public static bool In<T, TItem>(T value, params TItem[] list)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
<T> | value |
<TItem>[] | list |
Type Parameters
T
TItem
In<T, TItem>(T, SqlExpression<TItem>)
View Source
public static bool In<T, TItem>(T value, SqlExpression<TItem> query)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
<T> | value |
ServiceStack.OrmLite.SqlExpression<T> | query |
Type Parameters
T
TItem
Asc<T>(T)
View Source
public static string Asc<T>(T value)
Returns
System.String
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Desc<T>(T)
View Source
public static string Desc<T>(T value)
Returns
System.String
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
As<T>(T, Object)
View Source
public static string As<T>(T value, object asValue)
Returns
System.String
Parameters
Type | Name |
---|---|
<T> | value |
System.Object | asValue |
Type Parameters
T
Sum<T>(T)
View Source
public static T Sum<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Sum(String)
View Source
public static string Sum(string value)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | value |
Count<T>(T)
View Source
public static T Count<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
CountDistinct<T>(T)
View Source
public static T CountDistinct<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Count(String)
View Source
public static string Count(string value)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | value |
Min<T>(T)
View Source
public static T Min<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Min(String)
View Source
public static string Min(string value)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | value |
Max<T>(T)
View Source
public static T Max<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Max(String)
View Source
public static string Max(string value)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | value |
Avg<T>(T)
View Source
public static T Avg<T>(T value)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | value |
Type Parameters
T
Avg(String)
View Source
public static string Avg(string value)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | value |
AllFields<T>(T)
View Source
public static T AllFields<T>(T item)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | item |
Type Parameters
T
JoinAlias(String, String)
View Source
public static string JoinAlias(string property, string tableAlias)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | property |
System.String | tableAlias |
TableAlias(String, String)
View Source
public static string TableAlias(string property, string tableAlias)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | property |
System.String | tableAlias |
JoinAlias<T>(T, String)
View Source
public static T JoinAlias<T>(T property, string tableAlias)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | property |
System.String | tableAlias |
Type Parameters
T
TableAlias<T>(T, String)
View Source
public static T TableAlias<T>(T property, string tableAlias)
Returns
<T>
Parameters
Type | Name |
---|---|
<T> | property |
System.String | tableAlias |
Type Parameters
T
Custom(String)
View Source
public static string Custom(string customSql)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | customSql |
Custom<T>(String)
View Source
public static T Custom<T>(string customSql)
Returns
<T>
Parameters
Type | Name |
---|---|
System.String | customSql |
Type Parameters
T
Cast(Object, String)
View Source
public static string Cast(object value, string castAs)
Returns
System.String
Parameters
Type | Name |
---|---|
System.Object | value |
System.String | castAs |
IsJson(String)
Tests whether a string contains valid JSON. ISJSON does not check the uniqueness of keys at the same level.
View Source
public static bool? IsJson(string expression)
Returns
System.Nullable<System.Boolean>
: Returns True if the string contains valid JSON; otherwise, returns False. Returns null if expression is null.
ISJSON does not check the uniqueness of keys at the same level.
Parameters
Type | Name | Description |
---|---|---|
System.String | expression | The string to test. |
ISJSON does not check the uniqueness of keys at the same level. |
JsonValue<T>(String, String)
Extracts a scalar value from a JSON string.
View Source
public static T JsonValue<T>(string expression, string path)
Returns
<T>
:
Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.
If the value is greater than 4000 characters: <br /><br />
<ul>
<li>In lax mode, <strong>JSON_VALUE</strong> returns null.</li>
<li>In strict mode, <strong>JSON_VALUE</strong> returns an error.</li>
</ul>
<br />
If you have to return scalar values greater than 4000 characters, use <strong>OPENJSON</strong> instead of <strong>JSON_VALUE</strong>. For more info, see OPENJSON (Transact-SQL).
Parameters
Type | Name | Description |
---|---|---|
System.String | expression |
An expression. Typically the name of a variable or a column that contains JSON text.<br /><br /> If <strong>JSON_VALUE</strong> finds JSON that is not valid in expression before it finds the value identified by <em>path</em>, the function returns an error. If <strong>JSON_VALUE</strong> doesn't find the value identified by <em>path</em>, it scans the entire text and returns an error if it finds JSON that is not valid anywhere in <em>expression</em>.
|
| System.String
| path |
A JSON path that specifies the property to extract. For more info, see JSON Path Expressions (SQL Server).<br /><br />
In SQL Server 2017 and in Azure SQL Database, you can provide a variable as the value of <em>path</em>.<br /><br />
If the format of path isn't valid, <strong>JSON_VALUE</strong> returns an error.<br /><br />
|
Type Parameters
T
JsonValue(String, String)
Extracts a scalar value from a JSON string.
View Source
public static string JsonValue(string expression, string path)
Returns
System.String
:
Returns a single text value of type nvarchar(4000). The collation of the returned value is the same as the collation of the input expression.
If the value is greater than 4000 characters: <br /><br />
<ul>
<li>In lax mode, <strong>JSON_VALUE</strong> returns null.</li>
<li>In strict mode, <strong>JSON_VALUE</strong> returns an error.</li>
</ul>
<br />
If you have to return scalar values greater than 4000 characters, use <strong>OPENJSON</strong> instead of <strong>JSON_VALUE</strong>. For more info, see OPENJSON (Transact-SQL).
Parameters
Type | Name | Description |
---|---|---|
System.String | expression |
An expression. Typically the name of a variable or a column that contains JSON text.<br /><br /> If <strong>JSON_VALUE</strong> finds JSON that is not valid in expression before it finds the value identified by <em>path</em>, the function returns an error. If <strong>JSON_VALUE</strong> doesn't find the value identified by <em>path</em>, it scans the entire text and returns an error if it finds JSON that is not valid anywhere in <em>expression</em>.
|
| System.String
| path |
A JSON path that specifies the property to extract. For more info, see JSON Path Expressions (SQL Server).<br /><br />
In SQL Server 2017 and in Azure SQL Database, you can provide a variable as the value of <em>path</em>.<br /><br />
If the format of path isn't valid, <strong>JSON_VALUE</strong> returns an error.<br /><br />
|
JsonQuery(String)
Extracts an object or an array from a JSON string.<br /><br /> To extract a scalar value from a JSON string instead of an object or an array, see JSON_VALUE(Transact-SQL). For info about the differences between <strong>JSON_VALUE</strong> and <strong>JSON_QUERY</strong>, see Compare JSON_VALUE and JSON_QUERY.
View Source
public static string JsonQuery(string expression)
Returns
System.String
:
Returns a JSON fragment of type T. The collation of the returned value is the same as the collation of the input expression.<br /><br />
If the value is not an object or an array:
<ul>
<li>In lax mode, <strong>JSON_QUERY</strong> returns null.</li>
<li>In strict mode, <strong>JSON_QUERY</strong> returns an error.</li>
</ul>
Parameters
Type | Name | Description |
---|---|---|
System.String | expression |
An expression. Typically the name of a variable or a column that contains JSON text.<br /><br /> If <strong>JSON_QUERY</strong> finds JSON that is not valid in <em>expression</em> before it finds the value identified by <em>path</em>, the function returns an error. If <strong>JSON_QUERY</strong> doesn't find the value identified by <em>path</em>, it scans the entire text and returns an error if it finds JSON that is not valid anywhere in <em>expression</em>.
|
JsonQuery<T>(String)
View Source
public static T JsonQuery<T>(string expression)
Returns
<T>
Parameters
Type | Name |
---|---|
System.String | expression |
Type Parameters
T
JsonQuery(String, String)
View Source
public static string JsonQuery(string expression, string path)
Returns
System.String
Parameters
Type | Name |
---|---|
System.String | expression |
System.String | path |
JsonQuery<T>(String, String)
View Source
public static T JsonQuery<T>(string expression, string path)
Returns
<T>
Parameters
Type | Name |
---|---|
System.String | expression |
System.String | path |
Type Parameters
T