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 |
|---|---|
| Database(DbConnection) | Initializes a new instance of the Database class using the provided connection. |
| Database(String, String) | Initializes a new instance of the Database class using the provided connection string and provider’s invariant name. |
Properties
| Name | Description |
|---|---|
| Configuration | Provides access to configuration options for this instance. |
| Connection | Gets the connection to associate with new commands. |
| Transaction | Gets or sets a transaction to associate with new commands. |
Methods
| Name | Description |
|---|---|
| Add | Recursively executes INSERT commands for the specified entity and all its one-to-one and one-to-many associations. |
| AddAsync | Recursively executes INSERT commands for the specified entity and all its one-to-one and one-to-many associations. |
| AsyncMap(SqlBuilder) | Maps the results of the query to dynamic objects. The query is deferred-executed. |
| AsyncMap(SqlBuilder, Type) | Maps the results of the query to objects of type specified by the resultType parameter. The query is deferred-executed. |
| AsyncMap<TResult>(SqlBuilder) | Maps the results of the query to TResult objects. The query is deferred-executed. |
| AsyncMap<TResult>(SqlBuilder, Func<DbDataReader, TResult>) | Maps the results of the query to TResult objects, using the provided mapper delegate. |
| CreateCommand | Creates and returns a DbCommand object from the specified sqlBuilder. |
| Dispose() | Releases all resources used by the current instance of the Database class. |
| Dispose(Boolean) | Releases the resources used by this Database instance. |
| EnsureConnectionOpen | Opens Connection (if it’s not open) and returns an IDisposable object you can use to close it (if it wasn’t open). |
| EnsureConnectionOpenAsync | Opens Connection (if it’s not open) and returns an IAsyncDisposable object you can use to close it (if it wasn’t open). |
| EnsureInTransaction() | Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing. |
| EnsureInTransaction(IsolationLevel) | Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing. |
| EnsureInTransactionAsync(CancellationToken) | Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing. |
| EnsureInTransactionAsync(IsolationLevel, CancellationToken) | Returns a virtual transaction that you can use to ensure a code block is always executed in a transaction, new or existing. |
| Execute | Executes the nonQuery command. Optionally uses a transaction and validates affected records value before committing. |
| ExecuteAsync | Executes the nonQuery command. Optionally uses a transaction and validates affected records value before committing. |
| Find<TEntity> | Gets the entity whose primary key matches the id parameter. |
| FindAsync<TEntity> | Gets the entity whose primary key matches the id parameter. |
| From(String) | Creates and returns a new SqlSet using the provided table name. |
| From(String, Type) | Creates and returns a new SqlSet using the provided table name. |
| From<TResult>(String) | Creates and returns a new SqlSet<TResult> using the provided table name. |
| FromQuery(SqlBuilder) | Creates and returns a new SqlSet using the provided defining query. |
| FromQuery(SqlBuilder, Type) | Creates and returns a new SqlSet using the provided defining query. |
| FromQuery<TResult>(SqlBuilder) | Creates and returns a new SqlSet<TResult> using the provided defining query. |
| FromQuery<TResult>(SqlBuilder, Func<DbDataReader, TResult>) | Creates and returns a new SqlSet<TResult> using the provided defining query and mapper. |
| LastInsertId | Gets the identity value of the last inserted record. |
| LastInsertIdAsync | Gets the identity value of the last inserted record. |
| Map(SqlBuilder) | Maps the results of the query to dynamic objects. The query is deferred-executed. |
| Map(SqlBuilder, Type) | Maps the results of the query to objects of type specified by the resultType parameter. The query is deferred-executed. |
| Map<TResult>(SqlBuilder) | Maps the results of the query to TResult objects. The query is deferred-executed. |
| Map<TResult>(SqlBuilder, Func<DbDataReader, TResult>) | Maps the results of the query to TResult objects, using the provided mapper delegate. |
| QuoteIdentifier | Given an unquoted identifier in the correct catalog case, returns the correct quoted form of that identifier. |
| Remove | Executes a DELETE command for the specified entity. |
| RemoveAsync | Executes a DELETE command for the specified entity. |
| Table(Type) | Returns the SqlTable instance for the specified entityType. |
| Table<TEntity>() | Returns the SqlTable<TEntity> instance for the specified TEntity. |
| Update(Object) | Executes an UPDATE command for the specified entity. |
| Update(Object, Object) | Executes an UPDATE command for the specified entity. |
| UpdateAsync(Object, CancellationToken) | Executes an UPDATE command for the specified entity. |
| UpdateAsync(Object, Object, CancellationToken) | Executes an UPDATE command for the specified entity. |