Interface IQueryProvider
Interface for provider, which know execute query.
Namespace: Kros.KORM.Query
Assembly: Kros.KORM.dll
Syntax
public interface IQueryProvider : IQueryProvider, IDisposable
Properties
DbProviderFactory
Returns DbProviderFactory for current provider.
Declaration
DbProviderFactory DbProviderFactory { get; }
Property Value
Type | Description |
---|---|
System.Data.Common.DbProviderFactory |
Methods
BeginTransaction(IsolationLevel)
Begins the transaction using the specified isolation level.
Declaration
ITransaction BeginTransaction(IsolationLevel isolationLevel)
Parameters
Type | Name | Description |
---|---|---|
System.Data.IsolationLevel | isolationLevel | The database isolation level with which the underlying store transaction will be created. |
Returns
Type | Description |
---|---|
ITransaction | ITransaction wrapping access to the underlying store's transaction object. |
CreateBulkInsert()
Creates instance of Kros.Data.BulkActions.IBulkInsert.
Declaration
IBulkInsert CreateBulkInsert()
Returns
Type | Description |
---|---|
Kros.Data.BulkActions.IBulkInsert | Instance of Kros.Data.BulkActions.IBulkInsert. |
CreateBulkUpdate()
Creates instance of Kros.Data.BulkActions.IBulkUpdate.
Declaration
IBulkUpdate CreateBulkUpdate()
Returns
Type | Description |
---|---|
Kros.Data.BulkActions.IBulkUpdate | Instance of Kros.Data.BulkActions.IBulkUpdate. |
CreateIdGenerator(String, Int32)
Creates the identifier generator.
Declaration
IIdGenerator CreateIdGenerator(string tableName, int batchSize)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName | Name of the database table. |
System.Int32 | batchSize | Size of inserting the batch. |
Returns
Type | Description |
---|---|
Kros.Data.IIdGenerator | The identifier generator. |
Execute<T>(IQuery<T>)
Executes the specified query.
Declaration
IEnumerable<T> Execute<T>(IQuery<T> query)
Parameters
Type | Name | Description |
---|---|---|
IQuery<T> | query | The query. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | IEnumerable of models, which was materialized by query. |
Type Parameters
Name | Description |
---|---|
T | Type of model result. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If query is null. |
ExecuteInTransactionAsync(Func<Task>)
Asynchronously executes action in transaction.
Declaration
Task ExecuteInTransactionAsync(Func<Task> action)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Threading.Tasks.Task> | action | Action which will be executed. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task that represents the asynchronous operation. |
ExecuteNonQuery(String)
Executes arbitrary query.
Declaration
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
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. |
ExecuteNonQueryAsync(String, CommandParameterCollection, CancellationToken)
Asynchronously executes arbitrary query with parameters.
Declaration
Task<int> ExecuteNonQueryAsync(string query, CommandParameterCollection parameters, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.String | query | Arbitrary SQL query. It should not be SELECT query. |
CommandParameterCollection | parameters | The query parameters. |
System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous operation. The task result contains the numbers of affected rows. |
ExecuteNonQueryAsync(String, CancellationToken)
Asynchronously executes arbitrary query.
Declaration
Task<int> ExecuteNonQueryAsync(string query, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.String | query | Arbitrary SQL query. It should not be SELECT query. |
System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous operation. The task result contains the numbers of affected rows. |
ExecuteNonQueryAsync(String, CancellationToken, Object[])
Asynchronously executes arbitrary query.
Declaration
Task<int> ExecuteNonQueryAsync(string query, CancellationToken cancellationToken = default(CancellationToken), params object[] paramValues)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | Arbitrary SQL query. It should not be SELECT query. |
System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
System.Object[] | paramValues | List of query parameters. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous operation. The task result contains the numbers of affected rows. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Number of parameters does not match. |
ExecuteNonQueryCommand(IDbCommand)
Executes the command.
Declaration
int ExecuteNonQueryCommand(IDbCommand command)
Parameters
Type | Name | Description |
---|---|---|
System.Data.IDbCommand | command | The command. |
Returns
Type | Description |
---|---|
System.Int32 | Number of affected rows. |
ExecuteNonQueryCommandAsync(DbCommand, CancellationToken)
Asynchronously executes the command.
Declaration
Task<int> ExecuteNonQueryCommandAsync(DbCommand command, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbCommand | command | The command. |
System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous save operation. The task result contains the numbers of affected rows. |
ExecuteScalar<T>(IQuery<T>)
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
object ExecuteScalar<T>(IQuery<T> query)
Parameters
Type | Name | Description |
---|---|---|
IQuery<T> | query | The query. |
Returns
Type | Description |
---|---|
System.Object | The first column of the first row in the result set, or a null if the result set is empty. Returns a maximum of 2033 characters. |
Type Parameters
Name | Description |
---|---|
T | Type of model. |
ExecuteScalarCommand(IDbCommand)
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
object ExecuteScalarCommand(IDbCommand command)
Parameters
Type | Name | Description |
---|---|---|
System.Data.IDbCommand | command | The command. |
Returns
Type | Description |
---|---|
System.Object | The first column of the first row in the result set, or a null reference (Nothingin Visual Basic) if the result set is empty. |
ExecuteScalarCommandAsync(DbCommand, CancellationToken)
Asynchronously 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
Task<object> ExecuteScalarCommandAsync(DbCommand command, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbCommand | command | The command. |
System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | The first column of the first row in the result set, or a null reference (Nothingin Visual Basic) if the result set is empty. |
ExecuteStoredProcedure<TResult>(String)
Executes the stored procedure with parameters and returns its result. The result can be scalar value (primitive or complex – class type), or a list of values (System.Collections.Generic.IEnumerable<T>).
Declaration
TResult ExecuteStoredProcedure<TResult>(string storedProcedureName)
Parameters
Type | Name | Description |
---|---|---|
System.String | storedProcedureName | Name of the stored procedure. |
Returns
Type | Description |
---|---|
TResult | Result of the stored procedure. |
Type Parameters
Name | Description |
---|---|
TResult | The type of the result. It can be scalar primitive or complex (class) value,
or System.Collections.Generic.IEnumerable<T> of some value. If the |
Examples
For the examples, we expect to have a Database initialized and a Person
class defined.
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime BDay { get; set; }
}
private Database _database = new Database(new SqlConnection("connection string"));</code></pre>
// Stored procedure returns a scalar value.
int intResult = _database.ExecuteStoredProcedure<int>("ProcedureName");
DateTime dateResult = _database.ExecuteStoredProcedure<DateTime>("ProcedureName");
// Stored procedure sets the value of output parameter.
var parameters = new CommandParameterCollection();
parameters.Add("@param1", 10);
parameters.Add("@param2", DateTime.Now);
parameters.Add("@outputParam", null, DbType.String, ParameterDirection.Output);
_database.ExecuteStoredProcedure<string>("ProcedureName", parameters);
Console.WriteLine(parameters["@outputParam"].Value);
// Stored procedure returns complex object.
Person person = _database.ExecuteStoredProcedure<Person>("ProcedureName");
// Stored procedure returns list of complex objects.
IEnumerable<Person> persons = _database.ExecuteStoredProcedure<IEnumerable<Person>>("ProcedureName");
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException |
ExecuteStoredProcedure<TResult>(String, CommandParameterCollection)
Declaration
TResult ExecuteStoredProcedure<TResult>(string storedProcedureName, CommandParameterCollection parameters)
Parameters
Type | Name | Description |
---|---|---|
System.String | storedProcedureName | Name of the stored procedure. |
CommandParameterCollection | parameters | The stored procedure parameters. Values of output parameters (System.Data.ParameterDirection.Output System.Data.ParameterDirection.InputOutput) are set back to corresponding parameter in collection |
Returns
Type | Description |
---|---|
TResult |
Type Parameters
Name | Description |
---|---|
TResult |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Value of any of the parameters in |
GetCommandForCurrentTransaction()
Vytvorí inicializovaný príkaz System.Data.Common.DbCommand, pre aktuálnu transakciu. Používa sa iba v rámci volania ExecuteInTransactionAsync(Func<Task>).
Declaration
DbCommand GetCommandForCurrentTransaction()
Returns
Type | Description |
---|---|
System.Data.Common.DbCommand | Inicializovaný príkaz. |
GetExpressionVisitor()
Get expression visitor for generating sql.
Declaration
ISqlExpressionVisitor GetExpressionVisitor()
Returns
Type | Description |
---|---|
ISqlExpressionVisitor |
SetParameterDbType(DbParameter, String, String)
Sets correct data type to parameter
, according to column columnName
in table tableName
. The method does not set general System.Data.Common.DbParameter.DbType,
but specific for given database (SqlParameter.SqlDbType
, OleDbParameter.OleDbType
).
Declaration
void SetParameterDbType(DbParameter parameter, string tableName, string columnName)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbParameter | parameter | The parameter to which the data type is set. |
System.String | tableName | Table name. |
System.String | columnName | Column name which data type is obtained. |
SupportsIdentity()
Returns, if provider support inserting into table, where primary key is set as Identity.
Declaration
bool SupportsIdentity()
Returns
Type | Description |
---|---|
System.Boolean | true if provider supports inserting into table, where primary key is set as identity. |
SupportsPrepareCommand()
Returns, if provider supports peparing of command (System.Data.Common.DbCommand.Prepare).
Declaration
bool SupportsPrepareCommand()
Returns
Type | Description |
---|---|
System.Boolean | true if provider supports preparing command, otherwise false. |