/// <summary> /// 使用完整的LamadaQuery查询 /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="query"></param> /// <param name="cacheKey">cacheKey</param> /// <returns></returns> public override List <TModel> QueryOrFromCache <TModel>(LambdaQuery <TModel> query, out string cacheKey) { cacheKey = ""; CheckTableCreated <TModel>(); List <TModel> list = new List <TModel>(); if (query.SkipPage > 0)//按分页 { list = QueryResult <TModel>(query); if (SettingConfig.AutoTrackingModel && query.__TrackingModel) { SetOriginClone(list); } return(list); } cacheKey = ""; System.Data.Common.DbDataReader reader; query.FillParames(this); var sql = query.GetQuery(); var cacheTime = query.__ExpireMinute; var compileSp = query.__CompileSp; double runTime = 0; var db = GetDBHelper(AccessType.Read); if (cacheTime <= 0) { list = SqlStopWatch.ReturnList(() => { if (!compileSp) { 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; } 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); } return(list); }
/// <summary> /// 返回dynamic集合 /// </summary> /// <param name="sp"></param> /// <returns></returns> public override List <dynamic> RunDynamicList(string sp) { double runTime; //var reader = SqlStopWatch.RunDataReader(__DbHelper,sp); //ClearParame(); //return Dynamic.DynamicObjConvert.DataReaderToDynamic(reader,out runTime); var list = SqlStopWatch.ReturnList(() => { var db = GetDBHelper(DataAccessType.Read); var reader = db.RunDataReader(sp); return(Dynamic.DynamicObjConvert.DataReaderToDynamic(reader, out runTime)); }, sp); return(list); }
/// <summary> /// 执行存储过程返回结果集 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sp"></param> /// <returns></returns> public override List <T> RunList <T>(string sp) { var list = SqlStopWatch.ReturnList(() => { var db = GetDBHelper(DataAccessType.Read); var reader = db.RunDataReader(sp); ClearParame(); var pro = TypeCache.GetTable(typeof(T)).Fields; var mapping = pro.Select(b => new Attribute.FieldMapping() { ResultName = b.MemberName, QueryField = b.MemberName, PropertyType = b.PropertyType }).ToList(); var queryInfo = new LambdaQuery.Mapping.QueryInfo <T>(false, sp, mapping); return(ObjectConvert.DataReaderToSpecifiedList <T>(reader, queryInfo)); }, sp); return(list); }
/// <summary> /// 使用完整的LamadaQuery查询 /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="iQuery"></param> /// <param name="cacheKey">cacheKey</param> /// <returns></returns> public override List <TModel> QueryOrFromCache <TModel>(ILambdaQuery <TModel> iQuery, out string cacheKey) { var query = iQuery as LambdaQueryBase; 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; //query = null; return(list); }