Class DataManager
The DataManager is an abstract class in the Cuemon.Data namespace that can be used to implement execute commands of different database providers.
Namespace: Cuemon.Data
Assembly: Cuemon.Data.dll
Syntax
public abstract class DataManager
Properties
| Improve this DocConnectionString
Gets the string used to open the connection.
Declaration
public abstract string ConnectionString { get; }
Property Value
Type | Description |
---|---|
System.String | The connection string used to establish the initial connection. The exact contents of the connection string depend on the specific data source for this connection. |
DefaultConnectionString
Gets or sets the default connection string.
Declaration
public static string DefaultConnectionString { get; set; }
Property Value
Type | Description |
---|---|
System.String | The default connection string. |
TransientFaultHandlingOptionsCallback
Gets or sets the callback delegate that will provide options for transient fault handling.
Declaration
public abstract Action<TransientOperationOptions> TransientFaultHandlingOptionsCallback { get; set; }
Property Value
Type | Description |
---|---|
System.Action<TransientOperationOptions> | An System.Action<T> with the options for transient fault handling. |
Methods
| Improve this DocClone()
Creates a new object that is a copy of the current instance.
Declaration
public abstract DataManager Clone()
Returns
Type | Description |
---|---|
DataManager | A new object that is a copy of this instance. |
Execute(IDataCommand, DbParameter[])
Executes the command statement and returns the number of rows affected.
Declaration
public int Execute(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 value. |
ExecuteCommandCore(IDataCommand, DbParameter[])
Core method for executing all commands.
Declaration
protected virtual DbCommand ExecuteCommandCore(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Data.Common.DbCommand | System.Data.Common.DbCommand |
Remarks
If TransientFaultHandlingOptionsCallback has the EnableRecovery set to true
, this method will with it's default implementation try to gracefully recover from transient faults when the following condition is met:
RetryAttempts is less than the current attempt starting from 1 with a maximum of System.Byte.MaxValue retries
DetectionStrategy must evaluate to true
In case of a transient failure the default implementation will use RetryStrategy.
In any other case the originating exception is thrown.
ExecuteCore<T>(IDataCommand, DbParameter[], Func<DbCommand, T>)
Core method for executing methods on the System.Data.Common.DbCommand object resolved from the virtual ExecuteCommandCore(IDataCommand, DbParameter[]) method.
Declaration
protected virtual T ExecuteCore<T>(IDataCommand dataCommand, DbParameter[] parameters, Func<DbCommand, T> commandInvoker)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
System.Func<System.Data.Common.DbCommand, T> | commandInvoker | The function delegate that will invoke a method on the resolved System.Data.Common.DbCommand from the virtual ExecuteCommandCore(IDataCommand, DbParameter[]) method. |
Returns
Type | Description |
---|---|
T | A value of |
Type Parameters
Name | Description |
---|---|
T | The type to return. |
ExecuteExists(IDataCommand, DbParameter[])
Executes the command statement and returns true
if one or more records exists; otherwise false
.
Declaration
public bool ExecuteExists(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Boolean | A System.Boolean value. |
ExecuteIdentityDecimal(IDataCommand, DbParameter[])
Executes the command statement and returns an identity value as decimal.
Declaration
public abstract decimal ExecuteIdentityDecimal(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Decimal | System.Decimal |
ExecuteIdentityInt32(IDataCommand, DbParameter[])
Executes the command statement and returns an identity value as int.
Declaration
public abstract int ExecuteIdentityInt32(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int32 | System.Int32 |
ExecuteIdentityInt64(IDataCommand, DbParameter[])
Executes the command statement and returns an identity value as long.
Declaration
public abstract long ExecuteIdentityInt64(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int64 | System.Int64 |
ExecuteReader(IDataCommand, DbParameter[])
Executes the command statement and returns an object supporting the DbDataReader interface.
Declaration
public DbDataReader ExecuteReader(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Data.Common.DbDataReader | An object supporting the System.Data.Common.DbDataReader interface. |
ExecuteScalar(IDataCommand, DbParameter[])
Executes the command statement, and returns the value from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public object ExecuteScalar(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Object | The first column of the first row in the result from |
ExecuteScalarAs<TResult>(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as TResult
from the first column of the first row in the result set.
Additional columns or rows are ignored.
Declaration
public TResult ExecuteScalarAs<TResult>(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
TResult | The first column of the first row in the result from |
Type Parameters
Name | Description |
---|---|
TResult | The type of the return value. |
Remarks
This method uses System.Globalization.CultureInfo.InvariantCulture when casting the first column of the first row in the result from dataCommand
.
ExecuteScalarAs<TResult>(IDataCommand, IFormatProvider, DbParameter[])
Executes the command statement, and returns the value as TResult
from the first column of the first row in the result set.
Additional columns or rows are ignored.
Declaration
public TResult ExecuteScalarAs<TResult>(IDataCommand dataCommand, IFormatProvider provider, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.IFormatProvider | provider | An object that supplies culture-specific formatting information. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
TResult | The first column of the first row in the result from |
Type Parameters
Name | Description |
---|---|
TResult | The type of the return value. |
ExecuteScalarAsBoolean(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Boolean from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public bool ExecuteScalarAsBoolean(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Boolean | The first column of the first row in the result from |
ExecuteScalarAsByte(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Byte from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public byte ExecuteScalarAsByte(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Byte | The first column of the first row in the result from |
ExecuteScalarAsDateTime(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.DateTime from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public DateTime ExecuteScalarAsDateTime(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.DateTime | The first column of the first row in the result from |
ExecuteScalarAsDecimal(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Decimal from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public decimal ExecuteScalarAsDecimal(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Decimal | The first column of the first row in the result from |
ExecuteScalarAsDouble(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Double from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public double ExecuteScalarAsDouble(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Double | The first column of the first row in the result from |
ExecuteScalarAsGuid(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Guid from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public Guid ExecuteScalarAsGuid(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Guid | The first column of the first row in the result from |
ExecuteScalarAsInt16(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Int16 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public short ExecuteScalarAsInt16(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int16 | The first column of the first row in the result from |
ExecuteScalarAsInt32(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Int32 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public int ExecuteScalarAsInt32(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int32 | The first column of the first row in the result from |
ExecuteScalarAsInt64(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.Int64 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public long ExecuteScalarAsInt64(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Int64 | The first column of the first row in the result from |
ExecuteScalarAsSByte(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.SByte from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public sbyte ExecuteScalarAsSByte(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.SByte | The first column of the first row in the result from |
ExecuteScalarAsString(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.String from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public string ExecuteScalarAsString(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.String | The first column of the first row in the result from |
ExecuteScalarAsType(IDataCommand, Type, DbParameter[])
Executes the command statement, and returns the value as the specified returnType
from the first column of the first row in the result set.
Additional columns or rows are ignored.
Declaration
public object ExecuteScalarAsType(IDataCommand dataCommand, Type returnType, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Type | returnType | The type to return the first column value as. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Object | The first column of the first row in the result from |
Remarks
This method uses System.Globalization.CultureInfo.InvariantCulture when casting the first column of the first row in the result from dataCommand
.
ExecuteScalarAsType(IDataCommand, Type, IFormatProvider, DbParameter[])
Executes the command statement, and returns the value as the specified returnType
from the first column of the first row in the result set.
Additional columns or rows are ignored.
Declaration
public object ExecuteScalarAsType(IDataCommand dataCommand, Type returnType, IFormatProvider provider, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Type | returnType | The type to return the first column value as. |
System.IFormatProvider | provider | An object that supplies culture-specific formatting information. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Object | The first column of the first row in the result from |
ExecuteScalarAsUInt16(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.UInt16 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public ushort ExecuteScalarAsUInt16(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.UInt16 | The first column of the first row in the result from |
ExecuteScalarAsUInt32(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.UInt32 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public uint ExecuteScalarAsUInt32(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.UInt32 | The first column of the first row in the result from |
ExecuteScalarAsUInt64(IDataCommand, DbParameter[])
Executes the command statement, and returns the value as System.UInt64 from the first column of the first row in the result set. Additional columns or rows are ignored.
Declaration
public ulong ExecuteScalarAsUInt64(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.UInt64 | The first column of the first row in the result from |
ExecuteXmlString(IDataCommand, DbParameter[])
Executes the command statement and returns a string object with the retrieved XML.
Declaration
public virtual string ExecuteXmlString(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.String | An System.String object. |
GetCommandCore(IDataCommand, DbParameter[])
Gets the command object to be used by all execute related methods.
Declaration
protected abstract DbCommand GetCommandCore(IDataCommand dataCommand, params DbParameter[] parameters)
Parameters
Type | Name | Description |
---|---|---|
IDataCommand | dataCommand | The data command to execute. |
System.Data.Common.DbParameter[] | parameters | The parameters to use in the command. |
Returns
Type | Description |
---|---|
System.Data.Common.DbCommand |
GetReaderColumnNames(DbDataReader)
Creates and returns a sequence of column names resolved from the specified reader
.
Declaration
public static IEnumerable<string> GetReaderColumnNames(DbDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbDataReader | reader | The reader to resolve column names from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> | A sequence of column names resolved from the specified |
GetReaderColumns(DbDataReader)
Creates and returns a System.Collections.Generic.KeyValuePair<TKey,TValue> sequence of column names and values resolved from the specified reader
.
Declaration
public static IEnumerable<KeyValuePair<string, object>> GetReaderColumns(DbDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbDataReader | reader | The reader to resolve column names and values from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.Object>> | A System.Collections.Generic.KeyValuePair<TKey,TValue> sequence of column names and values resolved from the specified |
GetReaderColumnValues(DbDataReader)
Creates and returns a sequence of column values resolved from the specified reader
.
Declaration
public static IEnumerable<object> GetReaderColumnValues(DbDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbDataReader | reader | The reader to resolve column values from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Object> | A sequence of column values resolved from the specified |
ParseDbType(DbType)
Parses and returns a System.Type equivalent of dbType
.
Declaration
public static Type ParseDbType(DbType dbType)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DbType | dbType | The System.Data.DbType to parse. |
Returns
Type | Description |
---|---|
System.Type | A System.Type equivalent of |
ReaderToStream(DbDataReader)
Converts the given System.Data.Common.DbDataReader compatible object to a stream. Note: DbDataReader must return only one field (for instance, a XML field), otherwise an exception is thrown!
Declaration
public static Stream ReaderToStream(DbDataReader value)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbDataReader | value | The System.Data.Common.DbDataReader to build a stream from. |
Returns
Type | Description |
---|---|
System.IO.Stream | A System.IO.Stream object. |
ReaderToString(DbDataReader)
Converts the given System.Data.Common.DbDataReader compatible object to a string. Note: DbDataReader must return only one field, otherwise an exception is thrown!
Declaration
public static string ReaderToString(DbDataReader value)
Parameters
Type | Name | Description |
---|---|---|
System.Data.Common.DbDataReader | value | The System.Data.Common.DbDataReader to build a string from. |
Returns
Type | Description |
---|---|
System.String | A System.String object. |