View Source
Class NPocoDatabaseExtensions
Provides extension methods to NPoco Database class.
Assembly: Umbraco.Infrastructure.dll
Syntax
public static class NPocoDatabaseExtensions
Methods
View Source
EscapeAtSymbols(string)
This will escape single @ symbols for npoco values so it doesn't think it's a parameter
Declaration
public static string EscapeAtSymbols(string value)
Parameters
| Type |
Name |
Description |
| string |
value |
|
Returns
View Source
FetchByGroups<TResult, TSource>(IDatabase, IEnumerable<TSource>, int, Func<IEnumerable<TSource>, Sql<ISqlContext>>)
Declaration
public static IEnumerable<TResult> FetchByGroups<TResult, TSource>(this IDatabase db, IEnumerable<TSource> source, int groupSize, Func<IEnumerable<TSource>, Sql<ISqlContext>> sqlFactory)
Parameters
| Type |
Name |
Description |
| IDatabase |
db |
|
| IEnumerable<TSource> |
source |
|
| int |
groupSize |
|
| Func<IEnumerable<TSource>, Sql<ISqlContext>> |
sqlFactory |
|
Returns
| Type |
Description |
| IEnumerable<TResult> |
|
Type Parameters
| Name |
Description |
| TResult |
|
| TSource |
|
View Source
GetCurrentTransactionIsolationLevel(IDatabase)
Declaration
public static IsolationLevel GetCurrentTransactionIsolationLevel(this IDatabase database)
Parameters
| Type |
Name |
Description |
| IDatabase |
database |
|
Returns
| Type |
Description |
| IsolationLevel |
|
View Source
GetTypedCommand<TCommand>(IDbCommand)
Returns the underlying command as a typed command - this is used to unwrap the profiled mini profiler stuff
Declaration
public static TCommand GetTypedCommand<TCommand>(IDbCommand command) where TCommand : class, IDbCommand
Parameters
| Type |
Name |
Description |
| IDbCommand |
command |
|
Returns
| Type |
Description |
| TCommand |
|
Type Parameters
| Name |
Description |
| TCommand |
|
View Source
GetTypedConnection<TConnection>(IDbConnection?)
Returns the underlying connection as a typed connection - this is used to unwrap the profiled mini profiler stuff
Declaration
public static TConnection GetTypedConnection<TConnection>(IDbConnection? connection) where TConnection : class, IDbConnection
Parameters
| Type |
Name |
Description |
| IDbConnection |
connection |
|
Returns
| Type |
Description |
| TConnection |
|
Type Parameters
| Name |
Description |
| TConnection |
|
View Source
GetTypedTransaction<TTransaction>(IDbTransaction?)
Returns the underlying transaction as a typed transaction - this is used to unwrap the profiled mini profiler stuff
Declaration
public static TTransaction GetTypedTransaction<TTransaction>(IDbTransaction? transaction) where TTransaction : class, IDbTransaction
Parameters
| Type |
Name |
Description |
| IDbTransaction |
transaction |
|
Returns
| Type |
Description |
| TTransaction |
|
Type Parameters
| Name |
Description |
| TTransaction |
|
View Source
IncludeColumn(PocoData, KeyValuePair<string, PocoColumn>)
Determines whether a column should be part of a bulk-insert.
Declaration
public static bool IncludeColumn(PocoData pocoData, KeyValuePair<string, PocoColumn> column)
Parameters
| Type |
Name |
Description |
| PocoData |
pocoData |
The PocoData object corresponding to the record's type.
|
| KeyValuePair<string, PocoColumn> |
column |
The column.
|
Returns
| Type |
Description |
| bool |
A value indicating whether the column should be part of the bulk-insert.
|
Remarks
View Source
InsertOrUpdateAsync<T>(IUmbracoDatabase, T, string?, object?)
Safely inserts a record, or updates if it exists, based on a unique constraint.
Declaration
public static Task<RecordPersistenceType> InsertOrUpdateAsync<T>(this IUmbracoDatabase db, T poco, string? updateCommand, object? updateArgs) where T : class
Parameters
| Type |
Name |
Description |
| IUmbracoDatabase |
db |
|
| T |
poco |
|
| string |
updateCommand |
If the entity has a composite key they you need to specify the update command explicitly
|
| object |
updateArgs |
|
Returns
| Type |
Description |
| Task<RecordPersistenceType> |
The action that executed, either an insert or an update. If an insert occurred and a PK value got generated, the
poco object
passed in will contain the updated value.
|
Type Parameters
View Source
InsertOrUpdate<T>(IUmbracoDatabase, T)
Safely inserts a record, or updates if it exists, based on a unique constraint.
Declaration
[Obsolete("Use InsertOrUpdateAsync instead")]
public static RecordPersistenceType InsertOrUpdate<T>(this IUmbracoDatabase db, T poco) where T : class
Parameters
Returns
| Type |
Description |
| RecordPersistenceType |
The action that executed, either an insert or an update. If an insert occurred and a PK value got generated, the
poco object
passed in will contain the updated value.
|
Type Parameters
View Source
InsertOrUpdate<T>(IUmbracoDatabase, T, string?, object?)
Declaration
public static RecordPersistenceType InsertOrUpdate<T>(this IUmbracoDatabase db, T poco, string? updateCommand, object? updateArgs) where T : class
Parameters
| Type |
Name |
Description |
| IUmbracoDatabase |
db |
|
| T |
poco |
|
| string |
updateCommand |
|
| object |
updateArgs |
|
Returns
Type Parameters
View Source
QueryPaged<T>(IDatabase, long, Sql)
Iterates over the result of a paged data set with a db reader
Declaration
public static IEnumerable<T> QueryPaged<T>(this IDatabase database, long pageSize, Sql sql)
Parameters
| Type |
Name |
Description |
| IDatabase |
database |
|
| long |
pageSize |
The number of rows to load per page
|
| Sql |
sql |
|
Returns
| Type |
Description |
| IEnumerable<T> |
|
Type Parameters
View Source
QueryPaged<T>(IDatabase, long, Sql, Sql?)
Iterates over the result of a paged data set with a db reader
Declaration
public static IEnumerable<T> QueryPaged<T>(this IDatabase database, long pageSize, Sql sql, Sql? sqlCount)
Parameters
| Type |
Name |
Description |
| IDatabase |
database |
|
| long |
pageSize |
The number of rows to load per page
|
| Sql |
sql |
|
| Sql |
sqlCount |
Specify a custom Sql command to get the total count, if null is specified than the
auto-generated sql count will be used
|
Returns
| Type |
Description |
| IEnumerable<T> |
|
Type Parameters
View Source
TruncateTable(IDatabase, ISqlSyntaxProvider, string)
Declaration
public static void TruncateTable(this IDatabase db, ISqlSyntaxProvider sqlSyntax, string tableName)
Parameters