Class SqlTemplate
Represents a template for generating SQL queries in the persistence layer.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Persistence
Assembly: Umbraco.Infrastructure.dll
Syntax
public class SqlTemplate
Methods
View SourceArg(string)
Gets a named argument.
Declaration
public static object Arg(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| object |
ArgIn<T>(string)
Returns an enumerable representing the argument for a SQL WHERE IN clause.
Declaration
public static IEnumerable<T?> ArgIn<T>(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the argument to be used in the SQL template. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An System.Collections.Generic.IEnumerable<T> containing a single default value of type |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the elements in the argument list. |
Arg<T>(string)
Retrieves the value of a named argument used in a WHERE expression.
Declaration
public static T? Arg<T>(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the argument to retrieve. |
Returns
| Type | Description |
|---|---|
| T | The argument value of type |
Type Parameters
| Name | Description |
|---|---|
| T | The expected type of the argument value. |
Sql()
Returns a new NPoco.Sql<> instance initialized with the current SQL context and SQL string.
Declaration
public Sql<ISqlContext> Sql()
Returns
| Type | Description |
|---|---|
| Sql<ISqlContext> | A new NPoco.Sql<> instance. |
Sql(params object[])
Creates a new SQL query from the template, using the specified arguments.
Declaration
public Sql<ISqlContext> Sql(params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | Arguments to be formatted into the SQL template. |
Returns
| Type | Description |
|---|---|
| Sql<ISqlContext> | A new NPoco.Sql<> instance representing the formatted SQL query. |
Remarks
must pass the args, all of them, in the proper order, faster
SqlNamed(object)
Creates a SQL query using named arguments provided via an object's properties.
Declaration
public Sql<ISqlContext> SqlNamed(object nargs)
Parameters
| Type | Name | Description |
|---|---|---|
| object | nargs | An object whose public properties are used as named arguments for the SQL query template. |
Returns
| Type | Description |
|---|---|
| Sql<ISqlContext> | A NPoco.Sql<> instance representing the constructed SQL query. |
Remarks
can pass named args, not necessary all of them, slower so, not much different from what Where(...) does (ie reflection) Throws System.InvalidOperationException if required arguments are missing or if unknown arguments are provided. This method uses reflection to match property names to template argument names.