|
|
@ -18,12 +18,9 @@ using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data.Common;
|
|
|
|
using System.Data.Common;
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using Marr.Data.Mapping;
|
|
|
|
using Marr.Data.Mapping;
|
|
|
|
using Marr.Data.Converters;
|
|
|
|
|
|
|
|
using Marr.Data.Parameters;
|
|
|
|
using Marr.Data.Parameters;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Linq.Expressions;
|
|
|
@ -39,8 +36,6 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
#region - Contructor, Members -
|
|
|
|
#region - Contructor, Members -
|
|
|
|
|
|
|
|
|
|
|
|
private DbProviderFactory _dbProviderFactory;
|
|
|
|
|
|
|
|
private string _connectionString;
|
|
|
|
|
|
|
|
private DbCommand _command;
|
|
|
|
private DbCommand _command;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -55,43 +50,32 @@ namespace Marr.Data
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// A database provider agnostic initialization.
|
|
|
|
/// A database provider agnostic initialization.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="connection">The database connection string.</param>
|
|
|
|
/// <param name="connectionString">The database connection string.</param>
|
|
|
|
public DataMapper(DbProviderFactory dbProviderFactory, string connectionString)
|
|
|
|
public DataMapper(DbProviderFactory dbProviderFactory, string connectionString)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
SqlMode = SqlModes.StoredProcedure;
|
|
|
|
if (dbProviderFactory == null)
|
|
|
|
if (dbProviderFactory == null)
|
|
|
|
throw new ArgumentNullException("dbProviderFactory instance cannot be null.");
|
|
|
|
throw new ArgumentNullException("dbProviderFactory");
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(connectionString))
|
|
|
|
if (string.IsNullOrEmpty(connectionString))
|
|
|
|
throw new ArgumentNullException("connectionString cannot be null or empty.");
|
|
|
|
throw new ArgumentNullException("connectionString");
|
|
|
|
|
|
|
|
|
|
|
|
_dbProviderFactory = dbProviderFactory;
|
|
|
|
ProviderFactory = dbProviderFactory;
|
|
|
|
|
|
|
|
|
|
|
|
_connectionString = connectionString;
|
|
|
|
ConnectionString = connectionString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ConnectionString
|
|
|
|
public string ConnectionString { get; private set; }
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _connectionString;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DbProviderFactory ProviderFactory
|
|
|
|
public DbProviderFactory ProviderFactory { get; private set; }
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _dbProviderFactory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new command utilizing the connection string.
|
|
|
|
/// Creates a new command utilizing the connection string.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private DbCommand CreateNewCommand()
|
|
|
|
private DbCommand CreateNewCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DbConnection conn = _dbProviderFactory.CreateConnection();
|
|
|
|
DbConnection conn = ProviderFactory.CreateConnection();
|
|
|
|
conn.ConnectionString = _connectionString;
|
|
|
|
conn.ConnectionString = ConnectionString;
|
|
|
|
DbCommand cmd = conn.CreateCommand();
|
|
|
|
DbCommand cmd = conn.CreateCommand();
|
|
|
|
SetSqlMode(cmd);
|
|
|
|
SetSqlMode(cmd);
|
|
|
|
return cmd;
|
|
|
|
return cmd;
|
|
|
@ -155,23 +139,12 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
#region - SP / SQL Mode -
|
|
|
|
#region - SP / SQL Mode -
|
|
|
|
|
|
|
|
|
|
|
|
private SqlModes _sqlMode = SqlModes.StoredProcedure; // Defaults to SP.
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value that determines whether the DataMapper will
|
|
|
|
/// Gets or sets a value that determines whether the DataMapper will
|
|
|
|
/// use a stored procedure or a sql text command to access
|
|
|
|
/// use a stored procedure or a sql text command to access
|
|
|
|
/// the database. The default is stored procedure.
|
|
|
|
/// the database. The default is stored procedure.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public SqlModes SqlMode
|
|
|
|
public SqlModes SqlMode { get; set; }
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _sqlMode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_sqlMode = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sets the DbCommand objects CommandType to the current SqlMode.
|
|
|
|
/// Sets the DbCommand objects CommandType to the current SqlMode.
|
|
|
@ -257,7 +230,7 @@ namespace Marr.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OpenConnection();
|
|
|
|
OpenConnection();
|
|
|
|
|
|
|
|
|
|
|
|
List<TResult> list = new List<TResult>();
|
|
|
|
var list = new List<TResult>();
|
|
|
|
DbDataReader reader = null;
|
|
|
|
DbDataReader reader = null;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -290,7 +263,7 @@ namespace Marr.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(sql))
|
|
|
|
if (string.IsNullOrEmpty(sql))
|
|
|
|
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
|
|
|
|
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
|
|
|
|
else
|
|
|
|
|
|
|
|
Command.CommandText = sql;
|
|
|
|
Command.CommandText = sql;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -334,7 +307,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (DbDataAdapter adapter = _dbProviderFactory.CreateDataAdapter())
|
|
|
|
using (DbDataAdapter adapter = ProviderFactory.CreateDataAdapter())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Command.CommandText = sql;
|
|
|
|
Command.CommandText = sql;
|
|
|
|
adapter.SelectCommand = Command;
|
|
|
|
adapter.SelectCommand = Command;
|
|
|
@ -370,7 +343,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (DbDataAdapter adapter = _dbProviderFactory.CreateDataAdapter())
|
|
|
|
using (DbDataAdapter adapter = ProviderFactory.CreateDataAdapter())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Command.CommandText = sql;
|
|
|
|
Command.CommandText = sql;
|
|
|
|
adapter.SelectCommand = Command;
|
|
|
|
adapter.SelectCommand = Command;
|
|
|
@ -404,7 +377,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
adapter = _dbProviderFactory.CreateDataAdapter();
|
|
|
|
adapter = ProviderFactory.CreateDataAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
adapter.UpdateCommand = Command;
|
|
|
|
adapter.UpdateCommand = Command;
|
|
|
|
adapter.UpdateCommand.CommandText = sql;
|
|
|
|
adapter.UpdateCommand.CommandText = sql;
|
|
|
@ -437,7 +410,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
adapter = _dbProviderFactory.CreateDataAdapter();
|
|
|
|
adapter = ProviderFactory.CreateDataAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
adapter.InsertCommand = Command;
|
|
|
|
adapter.InsertCommand = Command;
|
|
|
|
adapter.InsertCommand.CommandText = sql;
|
|
|
|
adapter.InsertCommand.CommandText = sql;
|
|
|
@ -467,7 +440,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
adapter = _dbProviderFactory.CreateDataAdapter();
|
|
|
|
adapter = ProviderFactory.CreateDataAdapter();
|
|
|
|
|
|
|
|
|
|
|
|
adapter.DeleteCommand = Command;
|
|
|
|
adapter.DeleteCommand = Command;
|
|
|
|
adapter.DeleteCommand.CommandText = sql;
|
|
|
|
adapter.DeleteCommand.CommandText = sql;
|
|
|
@ -894,7 +867,7 @@ namespace Marr.Data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (MapRepository.Instance.EnableTraceLogging)
|
|
|
|
if (MapRepository.Instance.EnableTraceLogging)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
sb.AppendLine();
|
|
|
|
sb.AppendLine();
|
|
|
|
sb.AppendLine("==== Begin Query Trace ====");
|
|
|
|
sb.AppendLine("==== Begin Query Trace ====");
|
|
|
|
sb.AppendLine();
|
|
|
|
sb.AppendLine();
|
|
|
@ -920,10 +893,7 @@ namespace Marr.Data
|
|
|
|
|
|
|
|
|
|
|
|
private void UnbindEvents()
|
|
|
|
private void UnbindEvents()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (OpeningConnection != null)
|
|
|
|
|
|
|
|
OpeningConnection = null;
|
|
|
|
OpeningConnection = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (ClosingConnection != null)
|
|
|
|
|
|
|
|
ClosingConnection = null;
|
|
|
|
ClosingConnection = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|