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
파일 보기 프로젝트 열기: rasmuskl/ReSharperCourse 1 사용 예제들

공개 메소드들

메소드 설명
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