Example #1
0
        /// <summary>
        /// 返回首列结果
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        public override dynamic QueryScalar <TModel>(LambdaQuery <TModel> query)
        {
            query.TakeNum = 1;
            //using (var reader = GetQueryDynamicReader(query))
            //{
            //    var a = reader.Read();
            //    if (!a)
            //    {
            //        return null;
            //    }
            //    var result = reader[0];
            //    return result;
            //}
            var list = SqlStopWatch.ReturnData(() =>
            {
                return(GetQueryDynamicReader(query));
            }, (r) =>
            {
                var reader = r.reader;
                var a      = reader.Read();
                if (!a)
                {
                    return(null);
                }
                var result = reader[0];
                reader.Close();
                return(new object[] { result });
            });

            if (list == null)
            {
                return(null);
            }
            return(list.FirstOrDefault());
        }
Example #2
0
        /// <summary>
        /// 指定替换对象查询,并返回对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public override List <T> ExecList <T>(string sql, params Type[] types)
        {
            var list = SqlStopWatch.ReturnData(() =>
            {
                return(GetDataReader(sql, types));
            }, (r) =>
            {
                var pro     = TypeCache.GetTable(typeof(T)).Fields;
                var mapping = pro.Select(b => new Attribute.FieldMapping()
                {
                    ResultName = b.MemberName, QueryField = b.MemberName, PropertyType = b.PropertyType
                });
                var queryInfo = new LambdaQuery.Mapping.QueryInfo <T>(false, sql, mapping);
                return(ObjectConvert.DataReaderToSpecifiedList <T>(r.reader, queryInfo));
            });

            return(list);
            ////var reader = GetDataReader(sql, types);
            ////double runTime;
            ////return ObjectConvert.DataReaderToList<T>(reader, out runTime);
            //var pro = TypeCache.GetTable(typeof(T)).Fields;
            //var mapping = pro.Select(b => new Attribute.FieldMapping() { MappingName = b.MemberName, QueryName = b.MemberName }).ToList();
            //var queryInfo = new LambdaQuery.Mapping.QueryInfo<T>(false, sql, mapping);
            //var list = ObjectConvert.DataReaderToSpecifiedList<T>(reader, queryInfo);
        }
Example #3
0
        public override Dictionary <TKey, TValue> ToDictionary <TModel, TKey, TValue>(LambdaQuery <TModel> query)
        {
            var dic = SqlStopWatch.ReturnData(() =>
            {
                return(GetQueryDynamicReader(query));
            }, (r) =>
            {
                return(ObjectConvert.DataReadToDictionary <TKey, TValue>(r.reader));
            });

            return(dic);
        }
Example #4
0
        /// <summary>
        /// 返回dynamic集合
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public override List <dynamic> ExecDynamicList(string sql)
        {
            var list = SqlStopWatch.ReturnData(() =>
            {
                return(GetDataReader(sql));
            }, (r) =>
            {
                double runTime;
                return(Dynamic.DynamicObjConvert.DataReaderToDynamic(r.reader, out runTime));
            });

            return(list);
        }
Example #5
0
        public override Dictionary <TKey, TValue> ExecDictionary <TKey, TValue>(string sql, params Type[] types)
        {
            //var reader = GetDataReader(sql, types);
            //return ObjectConvert.DataReadToDictionary<TKey, TValue>(reader);

            var dic = SqlStopWatch.ReturnData(() =>
            {
                return(GetDataReader(sql, types));
            }, (r) =>
            {
                return(ObjectConvert.DataReadToDictionary <TKey, TValue>(r.reader));
            });

            return(dic);
        }
Example #6
0
        /// <summary>
        /// 返回动态对象
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public override List <dynamic> QueryDynamic(LambdaQueryBase query)
        {
            if (query.SkipPage > 0)
            {
                //int count;
                //var reader = GetPageReader(query);
                //var list = reader.GetDataDynamic(out count);
                //query.MapingTime += reader.runTime;
                //query.RowCount = count;
                //return list;

                var list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetPageReader(query));
                }, (r) =>
                {
                    int count;
                    var list2         = r.GetDataDynamic(out count);
                    query.MapingTime += r.runTime;
                    query.__RowCount  = count;
                    return(list2);
                });
                return(list);
            }
            else
            {
                //var reader = GetQueryDynamicReader(query);
                //double runTime;
                //var list = Dynamic.DynamicObjConvert.DataReaderToDynamic(reader, out runTime);
                //query.MapingTime += runTime;
                //query.RowCount = list.Count;
                //return list;

                var list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetQueryDynamicReader(query));
                }, (r) =>
                {
                    double runTime;
                    var list2         = Dynamic.DynamicObjConvert.DataReaderToDynamic(r.reader, out runTime);
                    query.MapingTime += runTime;
                    query.__RowCount  = list2.Count;
                    return(list2);
                });
                return(list);
            }
        }
Example #7
0
        /// <summary>
        /// 返回dynamic集合
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public override List <dynamic> ExecDynamicList(string sql, params Type[] types)
        {
            //var reader = GetDataReader(sql, types);
            //double runTime;
            //return Dynamic.DynamicObjConvert.DataReaderToDynamic(reader, out runTime);

            var list = SqlStopWatch.ReturnData(() =>
            {
                return(GetDataReader(sql, types));
            }, (r) =>
            {
                double runTime;
                return(Dynamic.DynamicObjConvert.DataReaderToDynamic(r.reader, out runTime));
            });

            return(list);
        }
Example #8
0
        /// <summary>
        /// 按select返回指定类型
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        public override List <TResult> QueryResult <TResult>(LambdaQueryBase query)
        {
            var queryInfo = new LambdaQuery.Mapping.QueryInfo <TResult>(false, query.GetQueryFieldString(), query.GetFieldMapping());

            if (query.SkipPage > 0)
            {
                //var reader = GetPageReader(query);
                //int count;
                //var list = reader.GetDataTResult<TResult>(queryInfo, out count);
                //query.RowCount = count;
                //return list;

                var list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetPageReader(query));
                }, (r) =>
                {
                    int count;
                    var list2        = r.GetDataTResult <TResult>(queryInfo, out count);
                    query.__RowCount = count;
                    return(list2);
                });
                return(list);
            }
            else
            {
                //var reader = GetQueryDynamicReader(query);
                //var list = ObjectConvert.DataReaderToSpecifiedList<TResult>(reader, queryInfo);
                //query.RowCount = list.Count;
                //return list;
                var list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetQueryDynamicReader(query));
                }, (r) =>
                {
                    var list2        = ObjectConvert.DataReaderToSpecifiedList <TResult>(r.reader, queryInfo);
                    query.__RowCount = list2.Count;
                    return(list2);
                });
                return(list);
            }
        }
Example #9
0
        /// <summary>
        /// 按匿名对象
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="query"></param>
        /// <param name="newExpression"></param>
        /// <returns></returns>
        public override List <TResult> QueryResult <TResult>(LambdaQueryBase query, NewExpression newExpression)
        {
            List <TResult> list;
            var            queryInfo = new LambdaQuery.Mapping.QueryInfo <TResult>(true, query.GetQueryFieldString(), null, newExpression.Constructor);

            if (query.SkipPage > 0)
            {
                //var reader = GetPageReader(query);
                //int count;
                //list = reader.GetDataTResult<TResult>(queryInfo, out count);
                //query.RowCount = count;
                list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetPageReader(query));
                }, (r) =>
                {
                    int count;
                    var list2      = r.GetDataTResult <TResult>(queryInfo, out count);
                    query.RowCount = count;
                    return(list2);
                });
            }
            else
            {
                //var reader = GetQueryDynamicReader(query);
                //list = ObjectConvert.DataReaderToSpecifiedList<TResult>(reader, queryInfo);
                list = SqlStopWatch.ReturnData(() =>
                {
                    return(GetQueryDynamicReader(query));
                }, (r) =>
                {
                    var list2 = ObjectConvert.DataReaderToSpecifiedList <TResult>(r.reader, queryInfo);
                    return(list2);
                });
            }
            return(list);
        }