Пример #1
0
        private Expression RecursivelyExtractWhereExpression(ParseTreeNode node, Expression p)
        {
            if (node.Term.Name == "Id")
            {
                string fieldName  = node.ChildNodes[0].Token.Text;
                int    indexField = SelectClause.IndexOf(fieldName);
                if (indexField == -1)
                {
                    throw new NotImplementedException("Use of a field in the WHERE clause without it being present in the SELECT clause is not supported at this time");
                }

                return(Expression.Convert(
                           Expression.ArrayAccess(
                               Expression.Convert(p, typeof(object[])),
                               Expression.Constant(indexField)),
                           _Mapping.GetPropertyInfo(FromTable, fieldName).PropertyType));
            }
            // TODO : all other types should be supported
            else if (node.Term.Name == "string")
            {
                return(Expression.Constant(node.Token.Value.ToString()));
            }
            else if (node.ChildNodes.Count() == 3)
            {
                Expression Variable = RecursivelyExtractWhereExpression(node.ChildNodes[0], p);
                string     Operator = node.ChildNodes[1].ChildNodes[0].Term.Name;
                Expression Operand  = RecursivelyExtractWhereExpression(node.ChildNodes[2], p);

                switch (Operator)
                {
                case "<": return(Expression.LessThan(Variable, Operand));

                case "<=": return(Expression.LessThanOrEqual(Variable, Operand));

                case ">": return(Expression.GreaterThan(Variable, Operand));

                case ">=": return(Expression.GreaterThanOrEqual(Variable, Operand));

                case "=": return(Expression.Equal(Variable, Operand));

                case "AND": return(Expression.And(Variable, Operand));

                case "OR": return(Expression.Or(Variable, Operand));

                default: throw new NotImplementedException(string.Format("{0} is not a supported operator", Operator));
                }
            }
            else
            {
                throw new BambooException("WHERE clause could not be successfully extracted");
            }
        }