Class Database
Represent access to ORM features.
For executing query and materializing models see:
Inheritance
Implements
Namespace: Kros.KORM
Assembly: Kros.KORM.dll
Syntax
public class Database : IDatabase, IDisposable
Constructors
Database(ConnectionStringSettings)
Initializes a new instance of the Database class.
Declaration
public Database(ConnectionStringSettings connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Configuration.ConnectionStringSettings | connectionString | The active connection. |
Database(ConnectionStringSettings, IQueryProviderFactory)
Initializes a new instance of the Database class.
Declaration
public Database(ConnectionStringSettings connectionString, IQueryProviderFactory queryProviderFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Configuration.ConnectionStringSettings | connectionString | The connection string settings. |
| IQueryProviderFactory | queryProviderFactory | The query provider factory, which know create query provider. |
Database(DbConnection)
Initializes a new instance of the Database class.
Declaration
public Database(DbConnection activeConnection)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.Common.DbConnection | activeConnection | The active connection. |
Database(DbConnection, IModelMapper)
Initializes a new instance of the Database class.
Declaration
public Database(DbConnection activeConnection, IModelMapper modelMapper)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.Common.DbConnection | activeConnection | The active connection. |
| IModelMapper | modelMapper | Model mapper, which will be used for mapping Object to Relation database. |
Database(DbConnection, IQueryProviderFactory)
Initializes a new instance of the Database class.
Declaration
public Database(DbConnection activeConnection, IQueryProviderFactory queryProviderFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.Common.DbConnection | activeConnection | The active connection. |
| IQueryProviderFactory | queryProviderFactory | The query provider factory, which know create query provider. |
Database(String, String)
Initializes a new instance of the Database class.
Declaration
public Database(string connectionString, string adoClientName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | Connection string. |
| System.String | adoClientName | Ado client name. (System.Data.SqlClient/System.Data.OleDb) |
Properties
DatabaseMapper
Gets the database mapper, which has mapping information for all tables in database
Declaration
public static IDatabaseMapper DatabaseMapper { get; }
Property Value
| Type | Description |
|---|---|
| IDatabaseMapper |
DbProviderFactory
Returns DbProviderFactory for current provider.
Declaration
public DbProviderFactory DbProviderFactory { get; }
Property Value
| Type | Description |
|---|---|
| System.Data.Common.DbProviderFactory |
DefaultModelFactory
Gets or sets the default model factory, which will be used for instanting and filling object from Ado.
Declaration
public static IModelFactory DefaultModelFactory { get; set; }
Property Value
| Type | Description |
|---|---|
| IModelFactory | The default model factory. |
DefaultModelMapper
Gets or sets the default model mapper, which will be used for mapping Object to Relation database.
Declaration
public static IModelMapper DefaultModelMapper { get; set; }
Property Value
| Type | Description |
|---|---|
| IModelMapper | The default model mapper. |
Log
Gets or sets the logging delegate.
Declaration
public static Action<string> Log { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Action<System.String> |
ModelBuilder
Gets the model builder for materializing data from ado to models.
Declaration
public IModelBuilder ModelBuilder { get; }
Property Value
| Type | Description |
|---|---|
| IModelBuilder |
Methods
BeginTransaction()
Declaration
public ITransaction BeginTransaction()
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(IsolationLevel)
Declaration
public ITransaction BeginTransaction(IsolationLevel isolationLevel)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IsolationLevel | isolationLevel |
Returns
| Type | Description |
|---|---|
| ITransaction |
CreateBulkInsert()
Creates instance of IBulkInsert.
Declaration
public IBulkInsert CreateBulkInsert()
Returns
| Type | Description |
|---|---|
| IBulkInsert | Instance of IBulkInsert. |
CreateBulkUpdate()
Creates instance of IBulkUpdate.
Declaration
public IBulkUpdate CreateBulkUpdate()
Returns
| Type | Description |
|---|---|
| IBulkUpdate | Instance of IBulkUpdate. |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposing |
ExecuteNonQuery(String)
Executes arbitrary query.
Declaration
public int ExecuteNonQuery(string query)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. It should not be SELECT query. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Number of affected rows. |
ExecuteNonQuery(String, CommandParameterCollection)
Executes arbitrary query with parameters.
Declaration
public int ExecuteNonQuery(string query, CommandParameterCollection parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. It should not be SELECT query. |
| CommandParameterCollection | parameters | The query parameters. |
Returns
| Type | Description |
|---|---|
| System.Int32 | Number of affected rows. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Value of any of the parameters is NULL and its data type (DataType) is not set. |
ExecuteScalar(String)
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
public string ExecuteScalar(string query)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. |
Returns
| Type | Description |
|---|---|
| System.String | The first column of the first row in the result set, or null if the result set is empty. Returns a maximum of 2033 characters. |
ExecuteScalar(String, Object[])
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
public string ExecuteScalar(string query, params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. |
| System.Object[] | args | The query parameters. |
Returns
| Type | Description |
|---|---|
| System.String | The first column of the first row in the result set, or null if the result set is empty. Returns a maximum of 2033 characters. |
ExecuteScalar<TResult>(String)
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
public TResult? ExecuteScalar<TResult>(string query)
where TResult : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. |
Returns
| Type | Description |
|---|---|
| System.Nullable<TResult> | The first column of the first row in the result set, or null if the result set is empty. Returns a maximum of 2033 characters. |
Type Parameters
| Name | Description |
|---|---|
| TResult |
ExecuteScalar<TResult>(String, Object[])
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
public TResult? ExecuteScalar<TResult>(string query, params object[] args)
where TResult : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | Arbitrary SQL query. |
| System.Object[] | args | The query parameters. |
Returns
| Type | Description |
|---|---|
| System.Nullable<TResult> | The first column of the first row in the result set, or null if the result set is empty. Returns a maximum of 2033 characters. |
Type Parameters
| Name | Description |
|---|---|
| TResult |
ExecuteStoredProcedure<TResult>(String)
Declaration
public TResult ExecuteStoredProcedure<TResult>(string storedProcedureName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | storedProcedureName |
Returns
| Type | Description |
|---|---|
| TResult |
Type Parameters
| Name | Description |
|---|---|
| TResult |
ExecuteStoredProcedure<TResult>(String, CommandParameterCollection)
Declaration
public TResult ExecuteStoredProcedure<TResult>(string storedProcedureName, CommandParameterCollection parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | storedProcedureName | |
| CommandParameterCollection | parameters |
Returns
| Type | Description |
|---|---|
| TResult |
Type Parameters
| Name | Description |
|---|---|
| TResult |
InitDatabaseForIdGenerator()
Declaration
public void InitDatabaseForIdGenerator()
Query<T>()
Gets the query builder for T creating and executing query for obtains models.
Declaration
public IQuery<T> Query<T>()
Returns
| Type | Description |
|---|---|
| IQuery<T> |
Type Parameters
| Name | Description |
|---|---|
| T | Type of model, for which querying. |