Search Results for

    Show / Hide Table of Contents
    View Source

    Class UmbracoDatabase

    Extends NPoco Database for Umbraco.

    Inheritance
    object
    Namespace: Umbraco.Cms.Infrastructure.Persistence
    Assembly: Umbraco.Infrastructure.dll
    Syntax
    public class UmbracoDatabase : Database, IUmbracoDatabase, IDatabase, IAsyncDatabase, IAsyncQueryDatabase, IAsyncBaseDatabase, IBaseCommonDatabase, IDatabaseConfig, IDatabaseQuery, IBaseDatabase
    Remarks

    Is used everywhere in place of the original NPoco Database object, and provides additional features such as profiling, retry policies, logging, etc.

    Is never created directly but obtained from the UmbracoDatabaseFactory.

    Constructors

    View Source

    UmbracoDatabase(string, ISqlContext, DbProviderFactory, ILogger<UmbracoDatabase>, IBulkSqlInsertProvider?, DatabaseSchemaCreatorFactory, IEnumerable<IMapper>?)

    Initializes a new instance of the UmbracoDatabase class.

    Declaration
    public UmbracoDatabase(string connectionString, ISqlContext sqlContext, DbProviderFactory provider, ILogger<UmbracoDatabase> logger, IBulkSqlInsertProvider? bulkSqlInsertProvider, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, IEnumerable<IMapper>? mapperCollection = null)
    Parameters
    Type Name Description
    string connectionString

    The connection string used to connect to the database.

    ISqlContext sqlContext

    The ISqlContext providing SQL context and helpers for database operations.

    DbProviderFactory provider

    The System.Data.Common.DbProviderFactory used to create database provider-specific instances.

    ILogger<UmbracoDatabase> logger

    The Microsoft.Extensions.Logging.ILogger<TCategoryName> instance for logging database operations.

    IBulkSqlInsertProvider bulkSqlInsertProvider

    An optional IBulkSqlInsertProvider for performing bulk SQL insert operations.

    DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory

    A factory for creating DatabaseSchemaCreator instances.

    IEnumerable<IMapper> mapperCollection

    An optional collection of NPoco.IMapper instances for mapping database entities.

    Remarks

    Used by UmbracoDatabaseFactory to create databases.

    Also used by DatabaseBuilder for creating databases and installing/upgrading.

    Properties

    View Source

    EnableSqlCount

    Gets or sets a value indicating whether to count all executed Sql statements.

    Declaration
    public bool EnableSqlCount { get; set; }
    Property Value
    Type Description
    bool
    View Source

    InTransaction

    Gets a value indicating whether the database is currently in a transaction.

    Declaration
    public bool InTransaction { get; }
    Property Value
    Type Description
    bool
    View Source

    InstanceId

    Gets the database instance unique identifier as a string.

    Declaration
    public string InstanceId { get; }
    Property Value
    Type Description
    string
    Remarks

    UmbracoDatabase returns the first eight digits of its unique Guid and, in some debug mode, the underlying database connection identifier (if any).

    View Source

    SqlContext

    Gets the Sql context.

    Declaration
    public ISqlContext SqlContext { get; }
    Property Value
    Type Description
    ISqlContext
    View Source

    SqlCount

    Gets the count of all executed Sql statements.

    Declaration
    public int SqlCount { get; }
    Property Value
    Type Description
    int

    Methods

    View Source

    BulkInsertRecords<T>(IEnumerable<T>)

    Inserts a collection of records of type T into the database in a single bulk operation.

    Declaration
    public int BulkInsertRecords<T>(IEnumerable<T> records)
    Parameters
    Type Name Description
    IEnumerable<T> records

    The collection of records to insert.

    Returns
    Type Description
    int

    The number of records successfully inserted.

    Type Parameters
    Name Description
    T

    The type of records to insert.

    View Source

    ExecuteNonQuery(DbCommand)

    Executes the specified database command as a non-query operation (such as INSERT, UPDATE, or DELETE) against the database.

    Declaration
    public int ExecuteNonQuery(DbCommand command)
    Parameters
    Type Name Description
    DbCommand command

    The System.Data.Common.DbCommand to execute.

    Returns
    Type Description
    int

    The number of rows affected by the command.

    View Source

    ExecuteScalar<T>(Sql)

    Declaration
    public T ExecuteScalar<T>(Sql sql)
    Parameters
    Type Name Description
    Sql sql
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    View Source

    ExecuteScalar<T>(string, CommandType, params object[])

    Declaration
    public T ExecuteScalar<T>(string sql, CommandType commandType, params object[] args)
    Parameters
    Type Name Description
    string sql
    CommandType commandType
    object[] args
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Remarks

    Be nice if handled upstream GH issue

    View Source

    ExecuteScalar<T>(string, params object[])

    Declaration
    public T ExecuteScalar<T>(string sql, params object[] args)
    Parameters
    Type Name Description
    string sql
    object[] args
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    View Source

    IsUmbracoInstalled()

    Determines whether the required Umbraco database tables are present, indicating that Umbraco is installed.

    Declaration
    public bool IsUmbracoInstalled()
    Returns
    Type Description
    bool

    True if the Umbraco database tables are detected to be installed; otherwise, false.

    View Source

    OnAbortTransaction()

    Declaration
    protected override void OnAbortTransaction()
    View Source

    OnBeginTransaction()

    Declaration
    protected override void OnBeginTransaction()
    View Source

    OnCompleteTransaction()

    Declaration
    protected override void OnCompleteTransaction()
    View Source

    OnConnectionOpened(DbConnection)

    Declaration
    protected override DbConnection OnConnectionOpened(DbConnection connection)
    Parameters
    Type Name Description
    DbConnection connection
    Returns
    Type Description
    DbConnection
    View Source

    OnException(Exception)

    Declaration
    protected override void OnException(Exception ex)
    Parameters
    Type Name Description
    Exception ex
    View Source

    OnExecutedCommand(DbCommand)

    Declaration
    protected override void OnExecutedCommand(DbCommand cmd)
    Parameters
    Type Name Description
    DbCommand cmd
    View Source

    OnExecutingCommand(DbCommand)

    Declaration
    protected override void OnExecutingCommand(DbCommand cmd)
    Parameters
    Type Name Description
    DbCommand cmd
    View Source

    ValidateSchema()

    Validates the current database schema and returns the result.

    Declaration
    public DatabaseSchemaResult ValidateSchema()
    Returns
    Type Description
    DatabaseSchemaResult

    A DatabaseSchemaResult representing the outcome of the schema validation process for the current database.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX