C# Класс BlogEngine.Core.Providers.DbConnectionHelper

Helper class for working with DbConnections.
This class is meant to reduce the amount of repeated code in database provider classes by pulling all the common actions into one spot. This should remove the many repetitive null checks on connections/parameters. This class handles the creation of DbConnection, setting its connection string, and opening the connection if possible. Usage is simple: using(var helper = new ConnectionHelper(provider)) { if (helper.HasConnection) { // do stuff } } Note: This class throws a NullReferenceException if its Provider.CreateParameter() method returns a null object. All of the methods in the DbBlogProvider class require parameterized queries, and previously each parameter created was being checked for null before proceeding. It's better to fail fast in this instance, to help creaters of custom implementations figure out what's wrong.
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
CreateCommand ( ) : DbCommand

Uses this ConnectionHelper instance's connection to create and return a new DbCommand instance.

CreateParameter ( string parameterName, object value ) : DbParameter

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.

CreateParameter ( string parameterName, object value, DbType dbType ) : DbParameter

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.

CreateParameter ( string parameterName, object value, DbType dbType, int size ) : DbParameter

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.

CreateTextCommand ( string commandText ) : DbCommand

Users this ConnectionHelper instance's connection to create and return a new DbCommand with the given command text. CommandType is automatically set to CommandType.Text.

DbConnectionHelper ( ConnectionStringSettings settings ) : System

Creates a new DbConnectionHelper instance from the given ConnectionStringSettings.

DbConnectionHelper ( string providerName, string connectionString ) : System

Creates a new DbConnectionHelper instance from the given provider name and database connection string..

Dispose ( ) : void

Disposes this DbConnectionHelper and its underlying connection.

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

Метод Описание
CheckDisposed ( ) : void
Dispose ( bool disposing ) : void

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

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

Uses this ConnectionHelper instance's connection to create and return a new DbCommand instance.
public CreateCommand ( ) : DbCommand
Результат System.Data.Common.DbCommand

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

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.
public CreateParameter ( string parameterName, object value ) : DbParameter
parameterName string The name of the parameter.
value object The value of the parameter.
Результат System.Data.Common.DbParameter

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

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.
public CreateParameter ( string parameterName, object value, DbType dbType ) : DbParameter
parameterName string The name of the parameter.
value object The value of the parameter.
dbType DbType The DB type.
Результат System.Data.Common.DbParameter

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

Uses this ConnectionHelper's Provider to create a DbParameter instance with the given parameter name and value.
public CreateParameter ( string parameterName, object value, DbType dbType, int size ) : DbParameter
parameterName string The name of the parameter.
value object The value of the parameter.
dbType DbType The DB type.
size int The size/length of the parameter.
Результат System.Data.Common.DbParameter

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

Users this ConnectionHelper instance's connection to create and return a new DbCommand with the given command text. CommandType is automatically set to CommandType.Text.
public CreateTextCommand ( string commandText ) : DbCommand
commandText string
Результат System.Data.Common.DbCommand

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

Creates a new DbConnectionHelper instance from the given ConnectionStringSettings.
public DbConnectionHelper ( ConnectionStringSettings settings ) : System
settings System.Configuration.ConnectionStringSettings
Результат System

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

Creates a new DbConnectionHelper instance from the given provider name and database connection string..
public DbConnectionHelper ( string providerName, string connectionString ) : System
providerName string
connectionString string
Результат System

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

Disposes this DbConnectionHelper and its underlying connection.
public Dispose ( ) : void
Результат void