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() | Initializes a new instance of the Database class. | |
Database(IDbConnection) | Initializes a new instance of the Database class using the provided connection. | |
Database(String) | Initializes a new instance of the Database class using the provided connection string. | |
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. | |
Contains | Checks the existance of the entity, using the primary key value. | |
ContainsKey(Type, Object) | Checks the existance of an entity whose primary matches the id parameter. | |
ContainsKey<TEntity>(Object) | Checks the existance of an entity whose primary matches the id parameter. | |
CreateCommand(SqlBuilder) | Creates and returns an IDbCommand object from the specified sqlBuilder. | |
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. | |
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). | |
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. | |
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. | |
Execute(SqlBuilder, Int32, Boolean) | Executes the nonQuery command. Optionally uses a transaction and validates affected records value before committing. | |
Find(Type, Object) | Gets the entity whose primary key matches the id parameter. | |
Find<TEntity>(Object) | Gets the entity whose primary key matches the id parameter. | |
From(String) | Creates and returns a new SqlSet using the provided table name. | |
From(SqlBuilder) | Creates and returns a new SqlSet using the provided defining query. | |
From(String, Type) | Creates and returns a new SqlSet using the provided table name. | |
From(SqlBuilder, Type) | Creates and returns a new SqlSet using the provided defining query. | |
From<TResult>(String) | Creates and returns a new SqlSet<TResult> using the provided table name. | |
From<TResult>(SqlBuilder) | Creates and returns a new SqlSet<TResult> using the provided defining query. | |
From<TResult>(SqlBuilder, Func<IDataRecord, 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. | |
Map(SqlBuilder) | Maps the results of the query to dynamic objects. The query is deferred-executed. | |
Map(Type, SqlBuilder) | 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<IDataRecord, 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, including properly escaping any embedded quotes in the identifier. | |
Remove | Executes a DELETE command for the specified entity. | |
RemoveKey(Type, Object) | Executes a DELETE command for the entity whose primary key matches the id parameter. | |
RemoveKey<TEntity>(Object) | Executes a DELETE command for the entity whose primary key matches the id parameter. | |
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. |