622 lines
25 KiB
C#
622 lines
25 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections;
|
|
using AIMSModel;
|
|
using AIMSObjectQuery;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AIMSDAL
|
|
{
|
|
internal partial class DProgramException
|
|
{
|
|
#region 插入实体操作部份
|
|
/// <summary>
|
|
/// 插入
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>标识列值或影响的记录行数</returns>
|
|
internal static int Insert(SqlCommand cmd, ProgramException programException)
|
|
{
|
|
cmd.Parameters.Clear();
|
|
cmd.CommandText = "insert into ProgramException (Message,Source,StackTrace,TargetSite,IP,OperatorId,ExceptionTime) values (@Message,@Source,@StackTrace,@TargetSite,@IP,@OperatorId,@ExceptionTime);select @@identity";
|
|
//从实体中取出值放入Command的参数列表
|
|
cmd.Parameters.Add(new SqlParameter("@Message",programException.Message==null?(object)DBNull.Value:(object)programException.Message));
|
|
cmd.Parameters.Add(new SqlParameter("@Source",programException.Source==null?(object)DBNull.Value:(object)programException.Source));
|
|
cmd.Parameters.Add(new SqlParameter("@StackTrace",programException.StackTrace==null?(object)DBNull.Value:(object)programException.StackTrace));
|
|
cmd.Parameters.Add(new SqlParameter("@TargetSite",programException.TargetSite==null?(object)DBNull.Value:(object)programException.TargetSite));
|
|
cmd.Parameters.Add(new SqlParameter("@IP",programException.IP==null?(object)DBNull.Value:(object)programException.IP));
|
|
cmd.Parameters.Add(new SqlParameter("@OperatorId",programException.OperatorId.HasValue?(object)programException.OperatorId.Value:(object)DBNull.Value));
|
|
cmd.Parameters.Add(new SqlParameter("@ExceptionTime",programException.ExceptionTime.HasValue?(object)programException.ExceptionTime.Value:(object)DBNull.Value));
|
|
return Convert.ToInt32(cmd.ExecuteScalar());
|
|
}
|
|
/// <summary>
|
|
/// 不使用事务的插入方法
|
|
/// </summary>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>标识列值或影响的记录行数</returns>
|
|
internal static int Insert(ProgramException programException)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return Insert(cmd, programException);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用事务的插入方法
|
|
/// </summary>
|
|
/// <param name="connection">实现共享Connection的对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>标识列值或影响的记录行数</returns>
|
|
internal static int Insert(Connection connection,ProgramException programException)
|
|
{
|
|
return Insert(connection.Command, programException);
|
|
}
|
|
#endregion
|
|
|
|
#region 删除实体操作
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int ExcuteDeleteCommand(SqlCommand cmd, ProgramException programException)
|
|
{
|
|
cmd.Parameters.Clear();
|
|
cmd.CommandText = "delete from ProgramException where Id=@Id";
|
|
//从实体中取出值放入Command的参数列表
|
|
cmd.Parameters.Add(new SqlParameter("@Id", programException.Id));
|
|
return cmd.ExecuteNonQuery();
|
|
}
|
|
/// <summary>
|
|
/// 不使用事务的删除方法
|
|
/// </summary>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Delete(ProgramException programException)
|
|
{
|
|
using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteDeleteCommand(cmd, programException);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 使用事务的删除方法
|
|
/// </summary>
|
|
/// <param name="connection">实现共享Connection的对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Delete(Connection connection,ProgramException programException)
|
|
{
|
|
return ExcuteDeleteCommand(connection.Command, programException);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行删除命令
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int ExcuteDeleteCommand(SqlCommand cmd, string oql, ParameterList parameters)
|
|
{
|
|
//解析过滤部份Sql语句
|
|
string filterString = SyntaxAnalyzer.ParseSql(oql, new ProgramExceptionMap());
|
|
if (filterString != string.Empty)
|
|
{
|
|
filterString = " where " + filterString;
|
|
}
|
|
cmd.Parameters.Clear();
|
|
cmd.CommandText = "delete from ProgramException " + filterString;
|
|
//添加参数
|
|
if (parameters != null)
|
|
{
|
|
foreach (string key in parameters.Keys)
|
|
{
|
|
cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
|
|
}
|
|
}
|
|
return cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 不使用事务的删除方法
|
|
/// </summary>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Delete(string oql, ParameterList parameters)
|
|
{
|
|
using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteDeleteCommand(cmd, oql, parameters);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用事务的删除方法
|
|
/// </summary>
|
|
/// <param name="connection">实现共享Connection的对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Delete(Connection connection, string oql, ParameterList parameters)
|
|
{
|
|
return ExcuteDeleteCommand(connection.Command, oql, parameters);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 更新实体操作
|
|
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int ExcuteUpdateCommand(SqlCommand cmd, ProgramException programException)
|
|
{
|
|
cmd.CommandText = "update ProgramException set Message=@Message,Source=@Source,StackTrace=@StackTrace,TargetSite=@TargetSite,IP=@IP,OperatorId=@OperatorId,ExceptionTime=@ExceptionTime where Id=@Id";
|
|
//从实体中取出值放入Command的参数列表
|
|
cmd.Parameters.Add(new SqlParameter("@Message",programException.Message==null?(object)DBNull.Value:(object)programException.Message));
|
|
cmd.Parameters.Add(new SqlParameter("@Source",programException.Source==null?(object)DBNull.Value:(object)programException.Source));
|
|
cmd.Parameters.Add(new SqlParameter("@StackTrace",programException.StackTrace==null?(object)DBNull.Value:(object)programException.StackTrace));
|
|
cmd.Parameters.Add(new SqlParameter("@TargetSite",programException.TargetSite==null?(object)DBNull.Value:(object)programException.TargetSite));
|
|
cmd.Parameters.Add(new SqlParameter("@IP",programException.IP==null?(object)DBNull.Value:(object)programException.IP));
|
|
cmd.Parameters.Add(new SqlParameter("@OperatorId",programException.OperatorId.HasValue?(object)programException.OperatorId.Value:(object)DBNull.Value));
|
|
cmd.Parameters.Add(new SqlParameter("@ExceptionTime",programException.ExceptionTime.HasValue?(object)programException.ExceptionTime.Value:(object)DBNull.Value));
|
|
cmd.Parameters.Add(new SqlParameter("@Id", programException.Id));
|
|
return cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 不使用事务的更新方法
|
|
/// </summary>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Update(ProgramException programException)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteUpdateCommand(cmd, programException);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 使用事务的更新方法
|
|
/// </summary>
|
|
/// <param name="connection">实现共享Connection的对象</param>
|
|
/// <param name="programException">实体类对象</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Update(Connection connection,ProgramException programException)
|
|
{
|
|
return ExcuteUpdateCommand(connection.Command, programException);
|
|
}
|
|
/// <summary>
|
|
/// 执行更新命令
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int ExcuteUpdateCommand(SqlCommand cmd, string oql, ParameterList parameters)
|
|
{
|
|
//解析过滤部份Sql语句
|
|
string updateString = SyntaxAnalyzer.ParseSql(oql, new ProgramExceptionMap());
|
|
cmd.CommandText = "update ProgramException set " + updateString;
|
|
cmd.Parameters.Clear();
|
|
//添加参数
|
|
if (parameters != null)
|
|
{
|
|
foreach (string key in parameters.Keys)
|
|
{
|
|
cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
|
|
}
|
|
}
|
|
return cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 不使用事务的更新方法
|
|
/// </summary>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Update(string oql, ParameterList parameters)
|
|
{
|
|
using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteUpdateCommand(cmd, oql, parameters);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用事务的更新方法
|
|
/// </summary>
|
|
/// <param name="connection">实现共享Connection的对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>影响的记录行数</returns>
|
|
internal static int Update(Connection connection, string oql, ParameterList parameters)
|
|
{
|
|
return ExcuteUpdateCommand(connection.Command, oql, parameters);
|
|
}
|
|
#endregion
|
|
|
|
#region 查询实体集合
|
|
/// <summary>
|
|
/// 执行Command获取对象列表
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象列表</returns>
|
|
internal static List<ProgramException> ExcuteSelectCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
|
|
{
|
|
List<ProgramException> programExceptionList = new List<ProgramException>();
|
|
using (SqlDataReader dr = cmd.ExecuteReader())
|
|
{
|
|
while (dr.Read())
|
|
{
|
|
ProgramException programException = DataReaderToEntity(dr);
|
|
programExceptionList.Add(programException);
|
|
}
|
|
}
|
|
return programExceptionList;
|
|
}
|
|
/// <summary>
|
|
/// 执行查询命令
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> ExcuteSelectCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
|
|
{
|
|
//解析过滤部份Sql语句
|
|
string filterString = SyntaxAnalyzer.ParseSql(oql, new ProgramExceptionMap());
|
|
if (filterString != string.Empty)
|
|
{
|
|
if(filterString.Trim().ToLower().IndexOf("order ")!=0)
|
|
filterString = " where " + filterString;
|
|
}
|
|
cmd.Parameters.Clear();
|
|
cmd.CommandText = "select * from ProgramException " + filterString;
|
|
//添加参数
|
|
if (parameters != null)
|
|
{
|
|
foreach (string key in parameters.Keys)
|
|
{
|
|
cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
|
|
}
|
|
}
|
|
return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据对象查询语句查询实体集合
|
|
/// </summary>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> Select()
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
cmd.CommandText = "select * from ProgramException";
|
|
return ExcuteSelectCommand(cmd, RecursiveType.Parent, 1);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据对象查询语句查询实体集合
|
|
/// </summary>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> Select(RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
cmd.CommandText = "select * from ProgramException";
|
|
return ExcuteSelectCommand(cmd, recursiveType, recursiveDepth);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据对象查询语句查询实体集合
|
|
/// </summary>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> Select(string oql, ParameterList parameters)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteSelectCommand(cmd, oql, parameters, RecursiveType.Parent, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据对象查询语句查询实体集合
|
|
/// </summary>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> Select(string oql, ParameterList parameters,RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteSelectCommand(cmd, oql, parameters, recursiveType, recursiveDepth);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据对象查询语句查询实体集合(启用事务)
|
|
/// </summary>
|
|
/// <param name="connection">连接对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象集合</returns>
|
|
internal static List<ProgramException> Select(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
return ExcuteSelectCommand(connection.Command, oql, parameters,recursiveType, recursiveDepth);
|
|
}
|
|
#endregion
|
|
|
|
#region 查询单个实体
|
|
|
|
/// <summary>
|
|
/// 递归查询单个实体
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException ExcuteSelectSingleCommand(SqlCommand cmd,RecursiveType recursiveType,int recursiveDepth)
|
|
{
|
|
ProgramException programException=null;
|
|
using (SqlDataReader dr = cmd.ExecuteReader())
|
|
{
|
|
if(dr.Read())
|
|
programException = DataReaderToEntity(dr);
|
|
}
|
|
if(programException==null)
|
|
return programException;
|
|
return programException;
|
|
}
|
|
/// <summary>
|
|
/// 更据对象查询语句递归查询单个实体
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException ExcuteSelectSingleCommand(SqlCommand cmd, string oql, ParameterList parameters,RecursiveType recursiveType,int recursiveDepth)
|
|
{
|
|
//解析过滤部份Sql语句
|
|
string filterString = SyntaxAnalyzer.ParseSql(oql, new ProgramExceptionMap());
|
|
if(filterString!=string.Empty)
|
|
{
|
|
filterString=" where "+filterString;
|
|
}
|
|
cmd.CommandText = "select * from ProgramException " + filterString;
|
|
cmd.Parameters.Clear();
|
|
//添加参数
|
|
if (parameters != null)
|
|
{
|
|
foreach (string key in parameters.Keys)
|
|
{
|
|
cmd.Parameters.Add(new SqlParameter(key, parameters[key]));
|
|
}
|
|
}
|
|
return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更据对象查询语句递归查询单个实体
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException SelectSingle(string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return ExcuteSelectSingleCommand(cmd, oql, parameters, recursiveType, recursiveDepth);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更据对象查询语句查询单个实体
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException SelectSingle(string oql, ParameterList parameters)
|
|
{
|
|
return SelectSingle(oql,parameters,RecursiveType.Parent,1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更据对象查询语句并启用事务查询单个实体
|
|
/// </summary>
|
|
/// <param name="connection">连接对象</param>
|
|
/// <param name="oql">对象查询语句</param>
|
|
/// <param name="parameters">参数列表</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException SelectSingle(Connection connection, string oql, ParameterList parameters, RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
return ExcuteSelectSingleCommand(connection.Command, oql, parameters, recursiveType, recursiveDepth);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更据主键值递归查询单个实体
|
|
/// </summary>
|
|
/// <param name="cmd">Command对象</param>
|
|
/// <param name="id">主键值</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体对象</returns>
|
|
internal static ProgramException SelectSingle(SqlCommand cmd, int? id,RecursiveType recursiveType,int recursiveDepth)
|
|
{
|
|
cmd.Parameters.Clear();
|
|
if(id.HasValue)
|
|
{
|
|
cmd.CommandText = "select * from ProgramException where Id=@pk";
|
|
cmd.Parameters.Add(new SqlParameter("@pk",id.Value));
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = "select * from ProgramException where Id is null";
|
|
}
|
|
return ExcuteSelectSingleCommand(cmd, recursiveType, recursiveDepth);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按主键字段查询特定实体
|
|
/// </summary>
|
|
/// <param name="id">主键值</param>
|
|
/// <returns>实体类对象</returns>
|
|
internal static ProgramException SelectSingle(int? id)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return SelectSingle(cmd,id,RecursiveType.Parent,1);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 按主键字段查询特定实体
|
|
/// </summary>
|
|
/// <param name="id">主键值</param>
|
|
/// <param name="recursiveType">递归类型</param>
|
|
/// <param name="recursiveDepth">递归深度</param>
|
|
/// <returns>实体类对象</returns>
|
|
internal static ProgramException SelectSingle(int? id, RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
using(SqlConnection conn=new SqlConnection(Connection.ConnectionString))
|
|
{
|
|
conn.Open();
|
|
using (SqlCommand cmd = conn.CreateCommand())
|
|
{
|
|
return SelectSingle(cmd,id, recursiveType, recursiveDepth);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用事务并按主键字段查询特定实体
|
|
/// </summary>
|
|
/// <param name="connection">连接对象</param>
|
|
/// <param name="id">主键值</param>
|
|
/// <returns>实体类对象</returns>
|
|
internal static ProgramException SelectSingle(Connection connection,int? id, RecursiveType recursiveType, int recursiveDepth)
|
|
{
|
|
return SelectSingle(connection.Command, id, recursiveType, recursiveDepth);
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 从DataReader中取出值生成实体对象
|
|
/// </summary>
|
|
/// <param name="searcher">查询对象</param>
|
|
/// <returns>过滤条件字符串</returns>
|
|
private static ProgramException DataReaderToEntity(SqlDataReader dr)
|
|
{
|
|
ProgramException entity = new ProgramException ();
|
|
if(dr["Id"]!=System.DBNull.Value)
|
|
{
|
|
entity.Id=Convert.ToInt32(dr["Id"]);
|
|
}
|
|
if(dr["Message"]!=System.DBNull.Value)
|
|
{
|
|
entity.Message=dr["Message"].ToString();
|
|
}
|
|
if(dr["Source"]!=System.DBNull.Value)
|
|
{
|
|
entity.Source=dr["Source"].ToString();
|
|
}
|
|
if(dr["StackTrace"]!=System.DBNull.Value)
|
|
{
|
|
entity.StackTrace=dr["StackTrace"].ToString();
|
|
}
|
|
if(dr["TargetSite"]!=System.DBNull.Value)
|
|
{
|
|
entity.TargetSite=dr["TargetSite"].ToString();
|
|
}
|
|
if(dr["IP"]!=System.DBNull.Value)
|
|
{
|
|
entity.IP=dr["IP"].ToString();
|
|
}
|
|
if(dr["OperatorId"]!=System.DBNull.Value)
|
|
{
|
|
entity.OperatorId=Convert.ToInt32(dr["OperatorId"]);
|
|
}
|
|
if(dr["ExceptionTime"]!=System.DBNull.Value)
|
|
{
|
|
entity.ExceptionTime=Convert.ToDateTime(dr["ExceptionTime"]);
|
|
}
|
|
return entity;
|
|
}
|
|
}
|
|
}
|
|
|