/// <summary> /// 根据参数条件筛选数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <param name="param"></param> /// <returns></returns> public IEnumerable <T> Query <T>(string sql, dynamic param, IDbConnection conn, IDbTransaction transaction) where T : class { CacheInfo cacheInfo = new CacheInfo(); if (param != null) { var identity = new Identity(sql, CommandType.Text, conn, null, param == null ? null : param.GetType(), null); cacheInfo.ParamReader = SqlCached.CreateParamInfoGenerator(identity, false); } IDbCommand cmd = null; try { cmd = SetupCommand(sql, cacheInfo.ParamReader, param, CommandType.Text, conn, transaction); IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DynamicBuilder <T> builder = DynamicBuilder <T> .CreateBuilder(reader); yield return(builder.Build(reader)); } reader.Close(); } finally { if (cmd != null) { cmd.Dispose(); } } }
/// <summary> /// 执行SQL 语句 /// </summary> /// <param name="sql"></param> /// <param name="param"></param> /// <param name="cmdType"></param> /// <param name="conn"></param> /// <param name="transaction"></param> private int Execute(string sql, object param, CommandType cmdType, IDbConnection conn, IDbTransaction transaction) { CacheInfo cacheInfo = new CacheInfo(); if (param != null) { var identity = new Identity(sql, cmdType, conn, null, param == null ? null : param.GetType(), null); cacheInfo.ParamReader = SqlCached.CreateParamInfoGenerator(identity, false); } int result = ExecuteCommandByParamReader(sql, param == null ? null : cacheInfo.ParamReader, param, cmdType, conn, transaction); return(result); }