/// <summary> /// 返回Sql和SqlParameter [] /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <returns></returns> public static Dictionary <string, string[]> ToSql <T>(this Queryable <T> queryable) { var sql = SqlSugarTool.GetQueryableSql <T>(queryable).ToString(); var pars = queryable.Params.ToArray(); var reval = new Dictionary <string, string[]>(); reval.Add(sql, pars.Select(it => it.ParameterName + ":" + it.Value).ToArray()); return(reval); }
/// <summary> /// 将Queryable转换为DataTable /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <returns></returns> public static DataTable ToDataTable <T>(this Queryable <T> queryable) { StringBuilder sbSql = SqlSugarTool.GetQueryableSql <T>(queryable); var dataTable = queryable.DB.GetDataTable(sbSql.ToString(), queryable.Params.ToArray()); queryable = null; sbSql = null; return(dataTable); }
/// <summary> /// 将Queryable转换为List《T》集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <returns></returns> public static List <T> ToList <T>(this Queryable <T> queryable) { StringBuilder sbSql = SqlSugarTool.GetQueryableSql <T>(queryable); var reader = queryable.DB.GetReader(sbSql.ToString(), queryable.Params.ToArray()); var reval = SqlSugarTool.DataReaderToList <T>(typeof(T), reader, queryable.Select.GetSelectFiles()); queryable = null; sbSql = null; return(reval); }