Database Class

Provides simple data access using SqlSet, SqlBuilder and SqlTable<TEntity>.

Inheritance Hierarchy

System.Object
  DbExtensions.Database

Namespace:  DbExtensions
Assembly: DbExtensions.dll

Syntax

public class Database : IDisposable

The Database type exposes the following members.

Constructors

  Name Description
Public method Database() Initializes a new instance of the Database class.
Public method Database(IDbConnection) Initializes a new instance of the Database class using the provided connection.
Public method Database(String) Initializes a new instance of the Database class using the provided connection string.
Public method Database(String, String) Initializes a new instance of the Database class using the provided connection string and provider’s invariant name.

Properties

  Name Description
Public property Configuration Provides access to configuration options for this instance.
Public property Connection Gets the connection to associate with new commands.
Public property Transaction Gets or sets a transaction to associate with new commands.

Methods

  Name Description
Public method Add Recursively executes INSERT commands for the specified entity and all its one-to-one and one-to-many associations.
Public method Contains Checks the existance of the entity, using the primary key value.
Public method ContainsKey(Type, Object) Checks the existance of an entity whose primary matches the id parameter.
Public method ContainsKey<TEntity>(Object) Checks the existance of an entity whose primary matches the id parameter.
Public method CreateCommand(SqlBuilder) Creates and returns an IDbCommand object from the specified sqlBuilder.
Public method CreateCommand(String, Object[]) Creates and returns an IDbCommand object using the provided commandText as a composite format string (as used on Format(String, Object[])), where the format items are replaced with appropiate parameter names, and the objects in the parameters array are added to the command’s Parameters collection.
Public method Dispose() Releases all resources used by the current instance of the Database class.
Protected method Dispose(Boolean) Releases the resources used by this Database instance.
Public methodCode example EnsureConnectionOpen Opens Connection (if it’s not open) and returns an IDisposable object you can use to close it (if it wasn’t open).
Public method EnsureInTransaction() Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing.
Public method EnsureInTransaction(IsolationLevel) Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing.
Public method Execute(String, Object[]) Creates and executes an IDbCommand using the provided commandText as a composite format string (as used on Format(String, Object[])), where the format items are replaced with appropiate parameter names, and the objects in the parameters array are added to the command’s Parameters collection.
Public method Execute(SqlBuilder, Int32, Boolean) Executes the nonQuery command. Optionally uses a transaction and validates affected records value before committing.
Public method Find(Type, Object) Gets the entity whose primary key matches the id parameter.
Public method Find<TEntity>(Object) Gets the entity whose primary key matches the id parameter.
Public method From(String) Creates and returns a new SqlSet using the provided table name.
Public method From(SqlBuilder) Creates and returns a new SqlSet using the provided defining query.
Public method From(String, Type) Creates and returns a new SqlSet using the provided table name.
Public method From(SqlBuilder, Type) Creates and returns a new SqlSet using the provided defining query.
Public method From<TResult>(String) Creates and returns a new SqlSet<TResult> using the provided table name.
Public method From<TResult>(SqlBuilder) Creates and returns a new SqlSet<TResult> using the provided defining query.
Public method From<TResult>(SqlBuilder, Func<IDataRecord, TResult>) Creates and returns a new SqlSet<TResult> using the provided defining query and mapper.
Public method LastInsertId Gets the identity value of the last inserted record.
Public method Map(SqlBuilder) Maps the results of the query to dynamic objects. The query is deferred-executed.
Public method Map(Type, SqlBuilder) Maps the results of the query to objects of type specified by the resultType parameter. The query is deferred-executed.
Public method Map<TResult>(SqlBuilder) Maps the results of the query to TResult objects. The query is deferred-executed.
Public method Map<TResult>(SqlBuilder, Func<IDataRecord, TResult>) Maps the results of the query to TResult objects, using the provided mapper delegate.
Public method QuoteIdentifier Given an unquoted identifier in the correct catalog case, returns the correct quoted form of that identifier, including properly escaping any embedded quotes in the identifier.
Public method Remove Executes a DELETE command for the specified entity.
Public method RemoveKey(Type, Object) Executes a DELETE command for the entity whose primary key matches the id parameter.
Public method RemoveKey<TEntity>(Object) Executes a DELETE command for the entity whose primary key matches the id parameter.
Public method Table(Type) Returns the SqlTable instance for the specified entityType.
Public method Table<TEntity>() Returns the SqlTable<TEntity> instance for the specified TEntity.
Public method Update(Object) Executes an UPDATE command for the specified entity.
Public method Update(Object, Object) Executes an UPDATE command for the specified entity.

See Also

Reference

DbExtensions Namespace

© Max Toro Q.