Esempio n. 1
0
        /// <summary>
        /// 使用完整的LamadaQuery查询
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="query"></param>
        /// <param name="cacheKey">cacheKey</param>
        /// <returns></returns>
        public override List <TModel> QueryList <TModel>(LambdaQuery <TModel> query, out string cacheKey)
        {
            cacheKey = "";
            CheckTableCreated <TModel>();
            if (query.SkipPage > 0)//按分页
            {
                return(Page <TModel, TModel>(query));
            }
            string sql = "";

            cacheKey = "";
            query.FillParames(this);
            sql = query.GetQuery();
            sql = _DBAdapter.SqlFormat(sql);
            System.Data.Common.DbDataReader reader;
            var           cacheTime = query.__ExpireMinute;
            var           compileSp = query.__CompileSp;
            List <TModel> list      = new List <TModel>();
            double        runTime   = 0;

            if (cacheTime <= 0)
            {
                if (!compileSp)
                {
                    if (query.TakeNum > 0)
                    {
                        dbHelper.AutoFormatWithNolock = false;
                    }
                    reader = dbHelper.ExecDataReader(sql);
                }
                else//生成储过程
                {
                    string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql);
                    reader = dbHelper.RunDataReader(sp);
                }
                query.ExecuteTime += dbHelper.ExecuteTime;
                list              = ObjectConvert.DataReaderToIModelList <TModel>(reader, out runTime, true);
                query.MapingTime += runTime;
            }
            else
            {
                list = MemoryDataCache.CacheService.GetCacheList <TModel>(sql, cacheTime, dbHelper, out cacheKey).Values.ToList();
            }
            ClearParame();
            query.RowCount = list.Count;
            if (SettingConfig.AutoTrackingModel && query.__TrackingModel)
            {
                SetOriginClone(list);
            }
            return(list);
        }