C# Класс DataAccessFramework.DataTool

An abstract class providing helper functionality to connect to a database.

This class provides functions that can simplfy common database access functionality, e.g. executing a stored procedure.

The tool itself is not tied to any specific database provider. Using this tool to execute database operations separates the application from the actual database server software.

The client code should also use functions in this class to create parameters to pass to the stored procedure. That will ensure that the parameters are compatible with the database provider.

Наследование: IDisposable
Показать файл Открыть проект

Открытые методы

Метод Описание
BeginTransaction ( ) : void

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling

CommitTransaction ( ) : void

Commits the transaction. Specialized classes should override this function and implement custom transaction handling

CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter

Creates database parameter for a binary value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.

CreateBoolParameter ( string parameterName, bool value ) : IDataParameter

Creates a database parameter for a Boolean value.

CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter

Creates a database parameter for a datetime value

CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter

Creates database parameter for a decimal value.

CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter

Creates database parameter for a GUID value.

CreateIntParameter ( string parameterName, int value ) : IDataParameter

Creates database parameter for an integer value.

CreateLongParameter ( string parameterName, long value ) : IDataParameter

Creates database parameter for an 64 bit integer value.

CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter

Creates a database parameter for a decimal value used for carrying monetary amount.

CreateStampParameter ( string parameterName, object stamp ) : IDataParameter

Creates a database parameter for a stamp value.

CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter

Creates database parameter for a string value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.

Dispose ( ) : void

Disposes the current instance.

ExecuteNonQuery ( string spName ) : int

Executes a stored procedure that does not return a result.

ExecuteQuery ( Query query ) : IDataReader

Executes a query represendted by a Query instance

ExecuteReader ( string spName ) : IDataReader

Executes a stored procedure that returns a single result set.

ExecuteReaderSingleRow ( string spName ) : IDataReader

Executes a stored procedure that returns a multiple result sets.

Executes a stored procedure that returns a single row.

ExecuteScalar ( string spName ) : object

Executes a stored procedure that returns a single value.

ExecuteSqlNonQuery ( string sql ) : int

Executes an sql statement that does not return a result.

ExecuteSqlReader ( string sql ) : IDataReader

Executes an SQL statement that returns an IDataReader

ExecuteSqlReaderSingleRow ( string sql ) : IDataReader

Executes an SQL statement that returns a single row.

ExecuteSqlScalar ( string sql ) : object

Executes an SQL text statement that returns a single value.

RollbackTransaction ( ) : void

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling

Защищенные методы

Метод Описание
AssertNotDisposed ( ) : void

Verifies that the object has not been disposed.

CreateCommand ( ) : IDbCommand

Template function for creating a command object.

The DataTool class will call this internally when executing a query

Dispose ( bool disposing ) : void

Template function for disposing resources.

GetConnection ( ) : IDbConnection

Template function for getting a connection object.

The DataTool class will call this internally when executing a query

GetTransaction ( ) : IDbTransaction

Template function for getting a transaction

The DataTool class will call this internally when executing a query

Приватные методы

Метод Описание
ExecuteNonQuery ( string commandText, CommandType commandType ) : int
ExecuteReader ( string sql, CommandType commandType, CommandBehavior behavior ) : IDataReader
ExecuteScalar ( string commandText, CommandType commandType ) : object

Описание методов

AssertNotDisposed() защищенный Метод

Verifies that the object has not been disposed.
/// The object has been disposed. ///
protected AssertNotDisposed ( ) : void
Результат void

BeginTransaction() публичный абстрактный Метод

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling
public abstract BeginTransaction ( ) : void
Результат void

CommitTransaction() публичный абстрактный Метод

Commits the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract CommitTransaction ( ) : void
Результат void

CreateBinaryParameter() публичный Метод

public CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
parameterName string
dataStream Stream
Результат IDataParameter

CreateBinaryParameter() публичный абстрактный Метод

Creates database parameter for a binary value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.
/// The size of value exceeds that specified by /// length ///
public abstract CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value byte /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
Результат IDataParameter

CreateBoolParameter() публичный абстрактный Метод

Creates a database parameter for a Boolean value.
public abstract CreateBoolParameter ( string parameterName, bool value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value bool /// The value of the parameter ///
Результат IDataParameter

CreateCommand() защищенный абстрактный Метод

Template function for creating a command object.
The DataTool class will call this internally when executing a query
protected abstract CreateCommand ( ) : IDbCommand
Результат IDbCommand

CreateDateTimeParameter() публичный абстрактный Метод

Creates a database parameter for a datetime value
public abstract CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.DateTime /// The value of the parameter ///
Результат IDataParameter

CreateDecimalParameter() публичный абстрактный Метод

Creates database parameter for a decimal value.
public abstract CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
Результат IDataParameter

CreateGuidParameter() публичный абстрактный Метод

Creates database parameter for a GUID value.
public abstract CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.Guid /// The value of the parameter ///
Результат IDataParameter

CreateIntParameter() публичный абстрактный Метод

Creates database parameter for an integer value.
public abstract CreateIntParameter ( string parameterName, int value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value int /// The value of the parameter ///
Результат IDataParameter

CreateLongParameter() публичный абстрактный Метод

Creates database parameter for an 64 bit integer value.
public abstract CreateLongParameter ( string parameterName, long value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value long /// The value of the parameter ///
Результат IDataParameter

CreateMoneyParameter() публичный абстрактный Метод

Creates a database parameter for a decimal value used for carrying monetary amount.
public abstract CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
Результат IDataParameter

CreateStampParameter() публичный абстрактный Метод

Creates a database parameter for a stamp value.
public abstract CreateStampParameter ( string parameterName, object stamp ) : IDataParameter
parameterName string /// The name of the parameter. ///
stamp object /// The value of the parameter ///
Результат IDataParameter

CreateStringParameter() публичный абстрактный Метод

Creates database parameter for a string value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.
/// The length of value exceeds that specified by /// length ///
public abstract CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value string /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
Результат IDataParameter

Dispose() публичный Метод

Disposes the current instance.
public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

Template function for disposing resources.
protected Dispose ( bool disposing ) : void
disposing bool /// Boolean value indicating if we are calling from dispose or the finalizer. /// true indicates we are calling from Dispose; false indicates /// we are calling from the finalizer. ///
Результат void

ExecuteNonQuery() публичный Метод

Executes a stored procedure that does not return a result.
public ExecuteNonQuery ( string spName ) : int
spName string /// Name of the stored procedure to execute. ///
Результат int

ExecuteQuery() публичный Метод

Executes a query represendted by a Query instance
public ExecuteQuery ( Query query ) : IDataReader
query DataAccessFramework.Querying.Query
Результат IDataReader

ExecuteReader() публичный Метод

Executes a stored procedure that returns a single result set.
public ExecuteReader ( string spName ) : IDataReader
spName string /// Name of the stored procedure to execute. ///
Результат IDataReader

ExecuteReaderSingleRow() публичный Метод

Executes a stored procedure that returns a multiple result sets. Executes a stored procedure that returns a single row.
public ExecuteReaderSingleRow ( string spName ) : IDataReader
spName string ///// Name of the stored procedure to execute. /////
Результат IDataReader

ExecuteScalar() публичный Метод

Executes a stored procedure that returns a single value.
public ExecuteScalar ( string spName ) : object
spName string /// Name of the stored procedure to execute. ///
Результат object

ExecuteSqlNonQuery() публичный Метод

Executes an sql statement that does not return a result.
public ExecuteSqlNonQuery ( string sql ) : int
sql string /// The SQL statement to execute ///
Результат int

ExecuteSqlReader() публичный Метод

Executes an SQL statement that returns an IDataReader
public ExecuteSqlReader ( string sql ) : IDataReader
sql string
Результат IDataReader

ExecuteSqlReaderSingleRow() публичный Метод

Executes an SQL statement that returns a single row.
public ExecuteSqlReaderSingleRow ( string sql ) : IDataReader
sql string
Результат IDataReader

ExecuteSqlScalar() публичный Метод

Executes an SQL text statement that returns a single value.
public ExecuteSqlScalar ( string sql ) : object
sql string
Результат object

GetConnection() защищенный абстрактный Метод

Template function for getting a connection object.
The DataTool class will call this internally when executing a query
protected abstract GetConnection ( ) : IDbConnection
Результат IDbConnection

GetTransaction() защищенный абстрактный Метод

Template function for getting a transaction
The DataTool class will call this internally when executing a query
protected abstract GetTransaction ( ) : IDbTransaction
Результат IDbTransaction

RollbackTransaction() публичный абстрактный Метод

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract RollbackTransaction ( ) : void
Результат void