Ejemplo n.º 1
0
        /// <summary>
        /// 根据Request中的QueryString获得Linq表达式
        /// </summary>
        /// <typeparam name="TEntity">实体对象</typeparam>
        /// <returns></returns>
        protected Expression <Func <TEntity, bool> > GetExpressionFromQueryString <TEntity>()
        {
            Expression <Func <TEntity, bool> > expr = null;
            var queryPairs = Request.GetQueryNameValuePairs().Where(q => q.Key.Equals("$format") == false);

            if (queryPairs.Count() > 0)
            {
                var filterGroup = new FilterGroup();
                foreach (var pairItem in queryPairs)
                {
                    filterGroup.Rules.Add(new FilterRule(pairItem.Key, pairItem.Value));
                }
                expr = filterGroup.BuildExpression <TEntity>();
            }
            return(expr);
        }