/// <summary> /// 返回动态对象的查询 /// </summary> /// <param name="query"></param> /// <returns></returns> internal System.Data.Common.DbDataReader GetQueryDynamicReader(LambdaQueryBase query) { CheckTableCreated(query.__MainType); string sql = ""; query.FillParames(this); sql = query.GetQuery(); sql = _DBAdapter.SqlFormat(sql); System.Data.Common.DbDataReader reader; var compileSp = query.__CompileSp; 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; ClearParame(); return(reader); }
/// <summary> /// 返回动态对象的查询 /// </summary> /// <param name="query"></param> /// <returns></returns> internal CallBackDataReader GetQueryDynamicReader(LambdaQueryBase query) { CheckTableCreated(query.__MainType); var sql = ""; query.FillParames(this); sql = query.GetQuery(); sql = _DBAdapter.SqlFormat(sql); System.Data.Common.DbDataReader reader; var compileSp = query.__CompileSp; var db = GetDBHelper(DataAccessType.Read); if (!compileSp) { if (query.TakeNum > 0) { db.AutoFormatWithNolock = false; } reader = db.ExecDataReader(sql); } else//生成储过程 { string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); reader = db.RunDataReader(sp); } query.ExecuteTime = db.ExecuteTime; ClearParame(); return(new CallBackDataReader(reader, null, sql)); }
/// <summary> /// 使用完整的LamadaQuery查询 /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="query"></param> /// <param name="cacheKey">cacheKey</param> /// <returns></returns> public override List <TModel> QueryOrFromCache <TModel>(LambdaQueryBase query, out string cacheKey) { cacheKey = ""; CheckTableCreated <TModel>(); List <TModel> list = new List <TModel>(); if (query.SkipPage > 0)//按分页 { list = QueryResult <TModel>(query); //分页不创建Clone //if (SettingConfig.AutoTrackingModel && query.__TrackingModel) //{ // SetOriginClone(list); //} return(list); } cacheKey = ""; System.Data.Common.DbDataReader reader; query.FillParames(this); var sql = query.GetQuery(); sql = _DBAdapter.SqlFormat(sql); var cacheTime = query.__ExpireMinute; var compileSp = query.__CompileSp; double runTime = 0; var db = GetDBHelper(DataAccessType.Read); if (cacheTime <= 0) { list = SqlStopWatch.ReturnList(() => { if (!compileSp || !_DBAdapter.CanCompileSP) { reader = db.ExecDataReader(sql); } else//生成储过程 { string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); reader = db.RunDataReader(sp); } query.ExecuteTime += db.ExecuteTime; var queryInfo = new LambdaQuery.Mapping.QueryInfo <TModel>(false, query.GetQueryFieldString(), query.GetFieldMapping()); return(ObjectConvert.DataReaderToSpecifiedList <TModel>(reader, queryInfo)); }, sql); query.MapingTime += runTime; //if(!string.IsNullOrEmpty(query.__RemoveInJionBatchNo)) //{ // Delete<InJoin>(b => b.BatchNo == query.__RemoveInJionBatchNo); // query.__RemoveInJionBatchNo = ""; //} } else { list = MemoryDataCache.CacheService.GetCacheList <TModel>(sql, query.GetFieldMapping(), cacheTime, db, out cacheKey).Values.ToList(); } ClearParame(); query.__RowCount = list.Count; if (SettingConfig.AutoTrackingModel && query.__TrackingModel) { SetOriginClone(list); } //query = null; return(list); }