Exemple #1
0
        private void ParseSelectManyExpression(Expression node)
        {
            var methodExpression = node as MethodCallExpression;

            Visit(methodExpression.Arguments[0]);
            if (!this.context.Fragment.HasOnlyParts(QueryPart.From))
            {
                var oldContext = this.context;
                this.context = oldContext.CopyTo();
                var queryTable = new QueryTable(oldContext.WrapToFragment(), this.context.GetTableAlias(oldContext.ExportType));
                this.context.Fragment.FromPart.Add(queryTable);
            }

            var joinContext = this.context.CopyTo();
            var joinParser  = new QueryExpressionParser(this.connection, joinContext);

            joinParser.Parse(methodExpression.Arguments[1]);

            Table table = null;

            if (joinContext.Fragment.HasOnlyParts(QueryPart.From) && joinContext.Fragment.PartsCount(QueryPart.From) == 1)
            {
                table       = joinContext.Fragment.FromPart.First();
                table.Alias = this.context.GetTableAlias(joinContext.ExportType);
            }
            else if (joinContext.Fragment.HasAnyParts())
            {
                table = new QueryTable(joinContext.WrapToFragment(), this.context.GetTableAlias(joinContext.ExportType));
            }

            var joinVisitor = new JoinExpressionVisitor(this.context);

            joinVisitor.Parse(methodExpression.Arguments[2]);

            if (table != null)
            {
                this.context.Fragment.FromPart.Add(new JoinTable(table)
                {
                    JoinMode = JoinMode.Default
                });
            }
        }
Exemple #2
0
        private void ParseJoinExpression(Expression node, JoinMode mode)
        {
            var methodExpression = node as MethodCallExpression;

            Visit(methodExpression.Arguments[0]);
            if (!this.context.Fragment.HasOnlyParts(QueryPart.From))
            {
                var oldContext = this.context;
                this.context = oldContext.CopyTo();
                var queryTable = new QueryTable(oldContext.WrapToFragment(), this.context.GetTableAlias(oldContext.ExportType));
                this.context.Fragment.FromPart.Add(queryTable);
            }

            var joinContext = this.context.CopyTo();
            var joinParser  = new QueryExpressionParser(this.connection, joinContext);

            joinParser.Parse(methodExpression.Arguments[1]);

            Table table;

            if (joinContext.Fragment.HasOnlyParts(QueryPart.From) && joinContext.Fragment.FromPart.Count == 1)
            {
                table       = joinContext.Fragment.FromPart.First();
                table.Alias = this.context.GetTableAlias(joinContext.ExportType);
            }
            else
            {
                table = new QueryTable(joinContext.WrapToFragment(), this.context.GetTableAlias(joinContext.ExportType));
            }

            var joinVisitor = new JoinExpressionVisitor(this.context);

            joinVisitor.Parse(methodExpression.Arguments[2], methodExpression.Arguments[3], methodExpression.Arguments[4]);
            this.context.Fragment.FromPart.Add(new JoinTable(table)
            {
                JoinMode = mode, JoinCondition = joinVisitor.Condition
            });
        }