/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.PagePowerSignPublic</returns> public DataAccess.Model.PagePowerSignPublic GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.PagePowerSignPublic model = null; Expression <Func <PagePowerSignPublic, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "Cname": model = list.SingleOrDefault(x => x.Cname == (string)value); expression = x => x.Cname == (string)value; break; case "Ename": model = list.SingleOrDefault(x => x.Ename == (string)value); expression = x => x.Ename == (string)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = PagePowerSignPublic.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取PagePowerSignPublic表记录时出现异常", e); return(null); } }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(DataAccess.Model.PagePowerSignPublic model) { //从缓存中读取记录列表 var list = GetList(); //从缓存中删除记录 DelCache(model.Id); //添加记录 list.Add(model); }
/// <summary> /// 给实体赋值 /// </summary> /// <param name="model">实体</param> /// <param name="dic">列名与值</param> public void SetModelValue(DataAccess.Model.PagePowerSignPublic model, Dictionary <string, object> dic) { if (model == null || dic == null) { return; } //遍历字典,逐个给字段赋值 foreach (var d in dic) { SetModelValue(model, d.Key, d.Value); } }
/// <summary> /// 将PagePowerSignPublic记录实体由普通的实体(DataAccess.Model.PagePowerSignPublic)转换为SubSonic插件生成的实体 /// </summary> /// <param name="model">普通的实体(DataAccess.Model.PagePowerSignPublic)</param> /// <returns>PagePowerSignPublic</returns> public PagePowerSignPublic Transform(DataAccess.Model.PagePowerSignPublic model) { if (model == null) { return(null); } return(new PagePowerSignPublic { Id = model.Id, Cname = model.Cname, Ename = model.Ename, }); }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(DataAccess.Model.PagePowerSignPublic model) { if (model == null) { return; } //从缓存中删除记录 DelCache(model.Id); //从缓存中读取记录列表 var list = GetList(); if (list == null) { list = new List <DataAccess.Model.PagePowerSignPublic>(); } //添加记录 list.Add(model); }
/// <summary> /// 返回实体中指定字段名的值 /// </summary> /// <param name="model">实体</param> /// <param name="colName">获取的字段名</param> /// <returns></returns> private object GetFieldValue(DataAccess.Model.PagePowerSignPublic model, string colName) { if (model == null || string.IsNullOrEmpty(colName)) { return(null); } //返回指定的列值 switch (colName) { case "Id": return(model.Id); case "Cname": return(model.Cname); case "Ename": return(model.Ename); } return(null); }
/// <summary> /// 给实体赋值 /// </summary> /// <param name="model">实体</param> /// <param name="colName">列名</param> /// <param name="value">值</param> public void SetModelValue(DataAccess.Model.PagePowerSignPublic model, string colName, object value) { if (model == null || string.IsNullOrEmpty(colName)) { return; } //返回指定条件的实体 switch (colName) { case "Id": model.Id = (int)value; break; case "Cname": model.Cname = (string)value; break; case "Ename": model.Ename = (string)value; break; } }