/// <summary> /// 返回Sql和参数信息 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="queryable">查询对象</param> /// <returns></returns> public static KeyValuePair <string, string[]> ToSql <T>(this Queryable <T> queryable) { var sql = SqlSugarTool.GetQueryableSql(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.First()); }
/// <summary> /// 将Queryable转换为DataTable /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="queryable">查询对象</param> /// <returns>DataTable</returns> public static DataTable ToDataTable <T>(this Queryable <T> queryable) { var sbSql = SqlSugarTool.GetQueryableSql(queryable); var dataTable = queryable.DB.GetDataTable(sbSql.ToString(), queryable.Params.ToArray()); queryable = null; sbSql = null; return(dataTable); }
/// <summary> /// 将Queryable转换T的集合 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="queryable">查询对象</param> /// <returns>T的集合</returns> public static List <T> ToList <T>(this Queryable <T> queryable) { var sbSql = SqlSugarTool.GetQueryableSql(queryable); var reader = queryable.DB.GetReader(sbSql.ToString(), queryable.Params.ToArray()); var reval = SqlSugarTool.DataReaderToList <T>(typeof(T), reader, queryable.SelectValue.GetSelectFiles()); queryable = null; sbSql = null; return(reval); }