/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS GetModelForCache(long id) { try { //从缓存中读取指定Id记录 var model = GetModelForCache(x => x.Id == id); if (model == null) { //从数据库中读取 var tem = SUPPLIERS.SingleOrDefault(x => x.Id == id); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取SUPPLIERS表记录时出现异常", e); return(null); } }
/// <summary> /// 获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS GetModel(long id, bool isCache = true) { //判断是否使用缓存 if (CommonBll.IsUseCache() && isCache) { //从缓存中获取List var list = GetList(); if (list == null) { return(null); } else { //在List查询指定主键Id的记录 return(list.SingleOrDefault(x => x.Id == id)); } } else { //从数据库中直接读取 var model = SUPPLIERS.SingleOrDefault(x => x.Id == id); if (model == null) { return(null); } else { //对查询出来的实体进行转换 return(Transform(model)); } } }
/// <summary> /// 获取SUP_BankName字段值 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="pkValue">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns></returns> public string GetSUP_BankName(Page page, int pkValue, bool isCache = true) { //判断是否启用缓存 if (isCache && CommonBll.IsUseCache()) { //从缓存中获取实体 var model = GetModelForCache(pkValue); return(model == null ? "" : model.SUP_BankName); } else { //从数据库中查询 var model = SUPPLIERS.SingleOrDefault(x => x.Id == pkValue); return(model == null ? "" : model.SUP_BankName); } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.SUPPLIERS model = null; Expression <Func <SUPPLIERS, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "SUP_ID": model = list.SingleOrDefault(x => x.SUP_ID == (string)value); expression = x => x.SUP_ID == (string)value; break; case "SUP_NAME": model = list.SingleOrDefault(x => x.SUP_NAME == (string)value); expression = x => x.SUP_NAME == (string)value; break; case "SUP_NICKNAME": model = list.SingleOrDefault(x => x.SUP_NICKNAME == (string)value); expression = x => x.SUP_NICKNAME == (string)value; break; case "SUP_TYPE": model = list.SingleOrDefault(x => x.SUP_TYPE == (int)value); expression = x => x.SUP_TYPE == (int)value; break; case "SUP_ADD": model = list.SingleOrDefault(x => x.SUP_ADD == (string)value); expression = x => x.SUP_ADD == (string)value; break; case "SUP_TEL": model = list.SingleOrDefault(x => x.SUP_TEL == (string)value); expression = x => x.SUP_TEL == (string)value; break; case "SUP_Email": model = list.SingleOrDefault(x => x.SUP_Email == (string)value); expression = x => x.SUP_Email == (string)value; break; case "SUP_ZIP": model = list.SingleOrDefault(x => x.SUP_ZIP == (string)value); expression = x => x.SUP_ZIP == (string)value; break; case "SUP_Contact": model = list.SingleOrDefault(x => x.SUP_Contact == (string)value); expression = x => x.SUP_Contact == (string)value; break; case "SUP_Mobile": model = list.SingleOrDefault(x => x.SUP_Mobile == (string)value); expression = x => x.SUP_Mobile == (string)value; break; case "SUP_CODE_ID": model = list.SingleOrDefault(x => x.SUP_CODE_ID == (string)value); expression = x => x.SUP_CODE_ID == (string)value; break; case "SUP_BankName": model = list.SingleOrDefault(x => x.SUP_BankName == (string)value); expression = x => x.SUP_BankName == (string)value; break; case "SUP_BankID": model = list.SingleOrDefault(x => x.SUP_BankID == (string)value); expression = x => x.SUP_BankID == (string)value; break; case "SUP_PASSWORD": model = list.SingleOrDefault(x => x.SUP_PASSWORD == (string)value); expression = x => x.SUP_PASSWORD == (string)value; break; case "Send_DAY": model = list.SingleOrDefault(x => x.Send_DAY == (int)value); expression = x => x.Send_DAY == (int)value; break; case "CRT_DATETIME": model = list.SingleOrDefault(x => x.CRT_DATETIME == (DateTime)value); expression = x => x.CRT_DATETIME == (DateTime)value; break; case "CRT_USER_ID": model = list.SingleOrDefault(x => x.CRT_USER_ID == (string)value); expression = x => x.CRT_USER_ID == (string)value; break; case "MOD_DATETIME": model = list.SingleOrDefault(x => x.MOD_DATETIME == (DateTime)value); expression = x => x.MOD_DATETIME == (DateTime)value; break; case "MOD_USER_ID": model = list.SingleOrDefault(x => x.MOD_USER_ID == (string)value); expression = x => x.MOD_USER_ID == (string)value; break; case "LAST_UPDATE": model = list.SingleOrDefault(x => x.LAST_UPDATE == (DateTime)value); expression = x => x.LAST_UPDATE == (DateTime)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = SUPPLIERS.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取SUPPLIERS表记录时出现异常", e); return(null); } }