Ejemplo n.º 1
0
        /// <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.º 2
0
        /// <summary>
        /// 将Queryable转换为DataTable
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="queryable">查询对象</param>
        /// <returns>DataTable</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);
        }
Ejemplo n.º 3
0
        /// <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)
        {
            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.SelectValue.GetSelectFiles());

            queryable = null;
            sbSql     = null;
            return(reval);
        }