Esempio n. 1
0
        /// <summary>
        /// 通用查询
        /// </summary>
        /// <param name="BtnG"></param>
        /// <param name="rp"></param>
        /// <param name="pageIndex"></param>
        /// <param name="allRows"></param>
        /// <param name="allPages"></param>
        /// <returns></returns>
        public static List <dynamic> DPGetQueryLst(SearchMod <T> aa, dynamic expression)
        {
            using (NERPEntities contex = new NERPEntities())
            {
                int skipCount = ((aa.page - 1) * aa.rp);
                var bb        = aa.ret; //匿名对象,用于显示输出
                //List<dynamic> list = contex.Set<T>().Select(c => aa).ToList<dynamic>();
                IQueryable <dynamic> query = aa.query;
                var custom = new SYS_ButtonGroup {
                    BG_Name = "BG_Name", BG_Name_En = "BG_Name_En"
                };
                //aa.where.Compile()(custom);
                //query.Where(aa.where);
                //query = aa.query;

                // var custom = expression.Compile()(expression);

                // var ww = expression.Compile()(custom);
                //表中有无法转换的字段,所以用动态类型进行转换
                List <dynamic> list = query.ToList <dynamic>();
                aa.total = list.Count();
                aa.total = aa.total / aa.rp + aa.total % aa.rp == 0 ? 0 : 1;
                List <dynamic> ret = aa.page == 0 ? list : list.Skip(skipCount).Take(aa.rp).ToList();
                return(ret);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 通用查询
        /// </summary>
        /// <param name="BtnG"></param>
        /// <param name="rp"></param>
        /// <param name="page"></param>
        /// <param name="allRows"></param>
        /// <param name="allPages"></param>
        /// <returns></returns>
        public static List <dynamic> DPGetQueryLst <T>(SearchMod <T> aa)
        {
            using (NERPEntities contex = new NERPEntities())
            {
                int            skipCount = ((aa.page - 1) * aa.rp);
                string         afg       = typeof(T).ToString();
                IQueryable <T> query     = null;

                ParameterExpression  left             = Expression.Parameter(typeof(T), "c");       //c=>
                ConstantExpression   _constExp        = Expression.Constant("aaa", typeof(string)); //一个常量
                MethodCallExpression _methodCallexp   = Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), _constExp);
                Expression <Action>  consoleLambdaExp = Expression.Lambda <Action>(_methodCallexp);

                //表中有无法转换的字段,所以用动态类型进行转换
                List <dynamic> list = query.Select(c => new { BG_Name = "123", BG_Name_En = "456", BG_OrderIndex = "678", BG_Desc = "789" }).ToList <dynamic>();
                aa.total = list.Count();
                aa.total = aa.total / aa.rp + aa.total % aa.rp == 0 ? 0 : 1;
                return(aa.page == 0 ? list : list.Skip(skipCount).Take(aa.rp).ToList());
            }
        }