コード例 #1
0
        public EntityQuery <DocumentManager.Web.Model.taxpayer> Search(EntityQuery <DocumentManager.Web.Model.taxpayer> aQuerable
                                                                       , TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            EntityQuery <DocumentManager.Web.Model.taxpayer> lQuerable = aQuerable;

            Expression filter    = Expression.Constant(true);
            Expression totalExpr = Expression.Constant(true);

            ParameterExpression lParam = Expression.Parameter(typeof(DocumentManager.Web.Model.taxpayer), "TaxPayer");

            {
                // Expression leftk = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty("taxpayer_group_id"));
                //Nullable<int> lValue = 0;

                //Expression rightk = Expression.Constant(0);
                //totalExpr = Expression.Equal(leftk, rightk);
            }

            Expression left  = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);

            switch (aTaxPayerSearchEntity.TPValueType)
            {
            case ValueType.VALUEBOOLEAN:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                break;

            case ValueType.VALUEINT:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                break;

            case ValueType.VALUESTR:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
            case SearchOperator.CONTAINS:
                filter = Expression.Call(Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                //totalExpr = Expression.And(filter, totalExpr);
                break;

            case SearchOperator.NOTCONTAINS:
                filter = Expression.Call(Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                filter = Expression.Not(filter);
                break;

            case SearchOperator.EQUAL:
                filter = Expression.Equal(left, right);
                break;

            case SearchOperator.NOEQUAL:
                filter = Expression.NotEqual(left, right);
                break;

            case SearchOperator.GREATER:
                filter = Expression.GreaterThan(left, right);
                break;

            case SearchOperator.LESS:
                filter = Expression.LessThan(left, right);
                break;

            case SearchOperator.GREATEREQUAL:
                filter = Expression.GreaterThanOrEqual(left, right);
                break;

            case SearchOperator.LESSEQUAL:
                filter = Expression.LessThanOrEqual(left, right);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchCondition)
            {
            case SearchCondition.AND:
                totalExpr = Expression.AndAlso(filter, totalExpr);
                break;

            case SearchCondition.OR:
                totalExpr = Expression.OrElse(filter, totalExpr);
                break;
            }

            //Expression pred = Expression.Lambda(totalExpr, lParam);
            //Expression whereExpression = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(DocumentManager.Web.Model.taxpayer) }, Expression.Constant(lQuerable), pred);
            //OrderBy部分排序
            //MethodCallExpression orderByCallExpression = Expression.Call(typeof(Queryable), queryCondition.IsDesc ? "OrderByDescending" : "OrderBy", new Type[] { typeof(TestUser), orderEntries[queryCondition.OrderField].OrderType }, whereExpression, Expression.Lambda(Expression.Property(param, orderEntries[queryCondition.OrderField].OrderStr), param));
            //EntityQuery<DocumentManager.Web.Model.taxpayer>()
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            return(lQuerable.Where((Expression <Func <DocumentManager.Web.Model.taxpayer, bool> >)Expression.Lambda(totalExpr, lParam)));
        }
コード例 #2
0
        private Expression CreateExpression(Expression aExpression, TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            //ParameterExpression lParam = Expression.Parameter(typeof(DocumentManager.Web.Model.taxpayer), "TaxPayer");

            Expression filter = Expression.Constant(true);

            Expression left  = Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);

            switch (aTaxPayerSearchEntity.TPValueType)
            {
            case ValueType.VALUEBOOLEAN:
                //right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean, typeof(bool?));
                break;

            case ValueType.VALUEINT:
                //right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                right = Expression.Constant(aTaxPayerSearchEntity.ValueInt, typeof(int?));
                break;

            case ValueType.VALUESTR:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
            case SearchOperator.CONTAINS:
                filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                //totalExpr = Expression.And(filter, totalExpr);
                break;

            case SearchOperator.NOTCONTAINS:
                filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                filter = Expression.Not(filter);
                break;

            case SearchOperator.EQUAL:
                filter = Expression.Equal(left, right);
                break;

            case SearchOperator.NOEQUAL:
                filter = Expression.NotEqual(left, right);
                break;

            case SearchOperator.GREATER:
                filter = Expression.GreaterThan(left, right);
                break;

            case SearchOperator.LESS:
                filter = Expression.LessThan(left, right);
                break;

            case SearchOperator.GREATEREQUAL:
                filter = Expression.GreaterThanOrEqual(left, right);
                break;

            case SearchOperator.LESSEQUAL:
                filter = Expression.LessThanOrEqual(left, right);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchCondition)
            {
            case SearchCondition.AND:
                filter = Expression.AndAlso(filter, aExpression);
                break;

            case SearchCondition.OR:
                filter = Expression.OrElse(filter, aExpression);
                break;
            }

            return(filter);
        }