Exemple #1
0
        protected object GetExpressionValue(Expression expression)
        {
            var constantExpression = expression as ConstantExpression;

            if (constantExpression != null)
            {
                return(constantExpression.Value);
            }

            var unaryExpression = expression as UnaryExpression;

            if (unaryExpression != null)
            {
                return(GetExpressionValue(unaryExpression.Operand));
            }

            var lambdaExpression = expression as LambdaExpression;

            if (lambdaExpression != null)
            {
                var binaryExpression = lambdaExpression.Body as BinaryExpression;
                if (binaryExpression != null)
                {
                    return(GetExpressionValue(AtkPartialEvaluator.Eval(binaryExpression.Right)));
                }

                var callExpression = lambdaExpression.Body as MethodCallExpression;
                if (callExpression != null)
                {
                    return(GetExpressionValue(callExpression));
                }
            }

            var memberExpression = expression as MemberExpression;

            if (memberExpression != null)
            {
                var fieldsOfObj  = memberExpression.Expression as ConstantExpression;
                var propertyInfo = memberExpression.Member as PropertyInfo;

                if (propertyInfo != null && !propertyInfo.PropertyType.IsSimpleType())
                {
                    return(propertyInfo.GetValue(fieldsOfObj, null));
                }

                var value = GetExpressionValue(memberExpression.Expression);
                return(this.ResolveValue((dynamic)memberExpression.Member, value));
            }

            throw new ArgumentException("Expected constant expression");
        }
        private void AddJoinCondition <TLeft, TRight>(Expression <Func <TLeft, TRight, bool> > expression,
                                                      string leftTableAlias              = null,
                                                      string rightTableAlias             = null,
                                                      LogicalOperator locLogicalOperator = LogicalOperator.NotSet)
        {
            var binaryExpression = expression.Body as BinaryExpression;

            this.Specification.Joins.Add(new JoinSpecification
            {
                LeftEntityType  = typeof(TLeft),
                LeftIdentifier  = this.GetMemberName(binaryExpression.Left),
                LeftTableAlias  = leftTableAlias,
                Operator        = this.OperatorString(binaryExpression.NodeType),
                RightEntityType = typeof(TRight),
                RightIdentifier = this.GetMemberName(AtkPartialEvaluator.Eval(binaryExpression.Right)),
                RightTableAlias = rightTableAlias,
                LogicalOperator = locLogicalOperator
            });
        }
        private JoinCondition GetCondition <TLeft, TRight>(LogicalOperator logicalOperator,
                                                           Expression <Func <TLeft, TRight, bool> > expression)
        {
            var binaryExpression = expression.Body as BinaryExpression;

            return(binaryExpression != null
                       ? new JoinCondition
            {
                LogicalOperator = logicalOperator,
                LeftTableAlias = this.currentTableSpecification.LeftAlias,
                LeftTableSchema = this.currentTableSpecification.LeftSchema,
                LeftTableName = this.currentTableSpecification.LeftTable,
                LeftIdentifier = this.GetMemberName(binaryExpression.Left),
                RightTableAlias = this.currentTableSpecification.RightAlias,
                RightTableSchema = this.currentTableSpecification.RightSchema,
                RightTableName = this.currentTableSpecification.RightTable,
                RightIdentifier = this.GetMemberName(AtkPartialEvaluator.Eval(binaryExpression.Right)),
                Operator = this.OperatorString(binaryExpression.NodeType)
            }
                       : default(JoinCondition));
        }
Exemple #4
0
        protected override void AddJoinCondition <TLeft, TRight>(
            Expression <Func <TLeft, TRight, bool> > expression,
            string leftTableAlias              = null,
            string rightTableAlias             = null,
            LogicalOperator locLogicalOperator = LogicalOperator.NotSet)
        {
            var body  = expression.Body as BinaryExpression;
            var joins = Specification.Joins;
            var joinSpecification1 = new JoinSpecification();

            joinSpecification1.LeftEntityType  = typeof(TLeft);
            joinSpecification1.LeftIdentifier  = GetMemberName(body.Left);
            joinSpecification1.LeftTableAlias  = leftTableAlias;
            joinSpecification1.Operator        = OperatorString(body.NodeType);
            joinSpecification1.RightEntityType = typeof(TRight);
            joinSpecification1.RightIdentifier = GetMemberName(AtkPartialEvaluator.Eval(body.Right));
            joinSpecification1.RightTableAlias = rightTableAlias;
            joinSpecification1.LogicalOperator = locLogicalOperator;
            var joinSpecification2 = joinSpecification1;

            joins.Add(joinSpecification2);
        }