/// <summary> /// 将查询自动转化为存储过程执行 /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="sql"></param> /// <returns></returns> public Dictionary <TKey, TValue> AutoSpQuery <TKey, TValue>(string sql, params Type[] types) { sql = AutoFormat(sql, types); sql = _DBAdapter.SqlFormat(sql); string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); System.Data.Common.DbDataReader reader = null; try { reader = helper.RunDataReader(sp); } catch (Exception ero) { if (ero.Message.Contains("找不到存储过程"))//删除后自动创建 { spCahe.Remove(sp); sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); reader = helper.RunDataReader(sp); } else { throw ero; } } ClearParame(); return(ObjectConvert.DataReadToDictionary <TKey, TValue>(reader)); }
/// <summary> /// 将查询自动转化为存储过程执行 /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="sql"></param> /// <returns></returns> public Dictionary <TKey, TValue> AutoSpQuery <TKey, TValue>(string sql, params Type[] types) { sql = AutoFormat(sql, types); sql = _DBAdapter.SqlFormat(sql); string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); System.Data.Common.DbDataReader reader = null; reader = dbHelper.RunDataReader(sp); ClearParame(); return(ObjectConvert.DataReadToDictionary <TKey, TValue>(reader)); }
public Dictionary <TKey, TValue> ExecDictionary <TKey, TValue>(string sql, params Type[] types) { var reader = GetDataReader(sql, types); return(ObjectConvert.DataReadToDictionary <TKey, TValue>(reader)); }