Example #1
0
 /// <summary>
 /// 获取指定Id记录
 /// </summary>
 /// <param name="id">主键Id</param>
 /// <param name="isCache">是否从缓存中读取</param>
 /// <returns>DataAccess.Model.RefTable</returns>
 public DataAccess.Model.RefTable GetModel(long id, bool isCache = true)
 {
     //判断是否使用缓存
     if (CommonBll.IsUseCache() && isCache)
     {
         //从缓存中获取List
         var list = GetList();
         if (list == null || list.Count == 0)
         {
             return(null);
         }
         else
         {
             //在List查询指定主键Id的记录
             return(list.SingleOrDefault(x => x.Id == id));
         }
     }
     else
     {
         //从数据库中直接读取
         var model = RefTable.SingleOrDefault(x => x.Id == id);
         if (model == null)
         {
             return(null);
         }
         else
         {
             //对查询出来的实体进行转换
             return(Transform(model));
         }
     }
 }
Example #2
0
        /// <summary>
        /// 从IIS缓存中获取指定条件的记录
        /// </summary>
        /// <param name="conditionColName">条件列名</param>
        /// <param name="value">条件值</param>
        /// <returns>DataAccess.Model.RefTable</returns>
        public DataAccess.Model.RefTable GetModelForCache(string conditionColName, object value)
        {
            try
            {
                //从缓存中获取List
                var list = GetList();
                DataAccess.Model.RefTable           model      = null;
                Expression <Func <RefTable, bool> > expression = null;

                //返回指定条件的实体
                switch (conditionColName)
                {
                case "Taxa_Id":
                    model      = list.SingleOrDefault(x => x.Taxa_Id == (long)value);
                    expression = x => x.Taxa_Id == (long)value;
                    break;

                case "Article_Id":
                    model      = list.SingleOrDefault(x => x.Article_Id == (long)value);
                    expression = x => x.Article_Id == (long)value;
                    break;


                default:
                    return(null);
                }

                if (model == null)
                {
                    //从数据库中读取
                    var tem = RefTable.SingleOrDefault(expression);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);
                        SetModelForCache(model);
                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取RefTable表记录时出现异常", e);

                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// 从IIS缓存中获取指定Id记录
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <returns>DataAccess.Model.RefTable</returns>
        public DataAccess.Model.RefTable GetModelForCache(long id)
        {
            try
            {
                //从缓存中读取指定Id记录
                var model = GetModelForCache(x => x.Id == id);

                if (model == null)
                {
                    //从数据库中读取
                    var tem = RefTable.SingleOrDefault(x => x.Id == id);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);
                        SetModelForCache(model);
                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取RefTable表记录时出现异常", e);

                return(null);
            }
        }