/// <summary> /// /// </summary> /// <param name="sql"></param> /// <param name="param"></param> /// <param name="totalRecord"></param> /// <returns></returns> public IEnumerable <dynamic> Query(string sql, DynamicParameters param, int totalRecord) { System.Data.IDbTransaction trans = null; IEnumerable <dynamic> result = null; using (System.Data.IDbConnection conn = this.GetOpenConnection()) { result = DMSDbAccess.Query(conn, string.Empty, sql, param, totalRecord, trans, true, 30); return(result); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <param name="param"></param> /// <param name="totalRecord"></param> /// <returns></returns> public IEnumerable <T> Query <T>(string sql, DynamicParameters param, int totalRecord) { try { System.Data.IDbTransaction trans = null; IEnumerable <T> result = null; using (System.Data.IDbConnection conn = this.GetOpenConnection()) { result = DMSDbAccess.Query <T>(conn, typeof(T).FullName, sql, param, totalRecord, trans, true, 30); return(result); } } catch (Exception ex) { Log.Debug(ReflectionUtils.GetMethodBaseInfo(System.Reflection.MethodBase.GetCurrentMethod()), ex.Message, ex); throw ex; } }
private static Func <IDataReader, object> GetStructDeserializer(Type type, int index) { // no point using special per-type handling here; it boils down to the same, plus not all are supported anyway (see: SqlDataReader.GetChar - not supported!) #pragma warning disable 618 if (type == typeof(char)) { // this *does* need special handling, though return(r => DMSDbAccess.ReadChar(r.GetValue(index))); } if (type == typeof(char?)) { return(r => DMSDbAccess.ReadNullableChar(r.GetValue(index))); } if (type.FullName == CacheMapper.LinqBinary) { return(r => Activator.CreateInstance(type, r.GetValue(index))); } #pragma warning restore 618 return(r => { var val = r.GetValue(index); return val is DBNull ? null : val; }); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ExcuteType"></param> /// <param name="countsql"></param> /// <param name="sql"></param> /// <param name="param"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalRecord"></param> /// <returns></returns> public ConditionResult <T> GetConditionResult <T>(DMSExcuteType ExcuteType, string countsql, string sql, DynamicParameters param, int pageIndex, int pageSize, int totalRecord) where T : class { ConditionResult <T> resultList = new ConditionResult <T>() { PageIndex = pageIndex, PageSize = pageSize, TotalRecord = 0, AllowPaging = true, ResultList = new List <T>(), }; using (System.Data.IDbConnection conn = this.GetOpenConnection()) { if (ExcuteType == DMSExcuteType.SELECT) { if (totalRecord == 0) { totalRecord = (int)DMSDbAccess.ExecuteScalar(conn, typeof(T).FullName, countsql, param); } resultList.TotalRecord = totalRecord; resultList.ResultList = DMSDbAccess.Query <T>(conn, typeof(T).FullName, sql, param, totalRecord, null, false, 30).ToList(); if (resultList.PageSize > 0) { resultList.TotalPage = resultList.TotalRecord / resultList.PageSize + (resultList.TotalRecord % resultList.PageSize == 0 ? 0 : 1); } } else if (ExcuteType == DMSExcuteType.DELETE || ExcuteType == DMSExcuteType.INSERT || ExcuteType == DMSExcuteType.UPDATE) { resultList.TotalRecord = DMSDbAccess.Execute(conn, typeof(T).FullName, sql, param); } conn.Close(); } return(resultList); }