Ejemplo n.º 1
0
        /// <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>
        /// 返回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 <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.First());
        }
Ejemplo n.º 3
0
        /// <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);
        }