/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 GetModelForCache(long id) { try { //从缓存中读取指定Id记录 var model = GetModelForCache(x => x.Id == id); if (model == null) { //从数据库中读取 var tem = CONTRACT00.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缓存中获取CONTRACT00表记录时出现异常", e); return(null); } }
/// <summary> /// 获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 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 = CONTRACT00.SingleOrDefault(x => x.Id == id); if (model == null) { return(null); } else { //对查询出来的实体进行转换 return(Transform(model)); } } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.CONTRACT00 model = null; Expression <Func <CONTRACT00, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "CONTRACT_ID": model = list.SingleOrDefault(x => x.CONTRACT_ID == (string)value); expression = x => x.CONTRACT_ID == (string)value; break; case "CONTRACT_TITLE": model = list.SingleOrDefault(x => x.CONTRACT_TITLE == (string)value); expression = x => x.CONTRACT_TITLE == (string)value; break; case "CONTRACTP_SIGN": model = list.SingleOrDefault(x => x.CONTRACTP_SIGN == (DateTime)value); expression = x => x.CONTRACTP_SIGN == (DateTime)value; break; case "CONTRACTP_STARTTIME": model = list.SingleOrDefault(x => x.CONTRACTP_STARTTIME == (DateTime)value); expression = x => x.CONTRACTP_STARTTIME == (DateTime)value; break; case "CONTRACTP_ENDTIME": model = list.SingleOrDefault(x => x.CONTRACTP_ENDTIME == (DateTime)value); expression = x => x.CONTRACTP_ENDTIME == (DateTime)value; break; case "USABLE": model = list.SingleOrDefault(x => x.USABLE == (byte)value); expression = x => x.USABLE == (byte)value; break; case "LOCK": model = list.SingleOrDefault(x => x.LOCK == (byte)value); expression = x => x.LOCK == (byte)value; break; case "FIRST_PARTY": model = list.SingleOrDefault(x => x.FIRST_PARTY == (string)value); expression = x => x.FIRST_PARTY == (string)value; break; case "SECEND_PARTY": model = list.SingleOrDefault(x => x.SECEND_PARTY == (string)value); expression = x => x.SECEND_PARTY == (string)value; break; case "Meno": model = list.SingleOrDefault(x => x.Meno == (string)value); expression = x => x.Meno == (string)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; case "STATUS": model = list.SingleOrDefault(x => x.STATUS == (byte)value); expression = x => x.STATUS == (byte)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = CONTRACT00.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取CONTRACT00表记录时出现异常", e); return(null); } }