Ejemplo n.º 1
0
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));
                var extract  = (LambdaExpression)methodCall.Arguments[1].Unwrap();
                var update   = methodCall.Arguments[2].Unwrap();

                if (!(sequence.Statement is SqlInsertStatement insertStatement))
                {
                    insertStatement    = new SqlInsertStatement(sequence.SelectQuery);
                    sequence.Statement = insertStatement;
                }

                if (insertStatement.Insert.Into == null)
                {
                    insertStatement.Insert.Into = (SqlTable)sequence.SelectQuery.From.Tables[0].Source;
                    insertStatement.SelectQuery.From.Tables.Clear();
                }

                if (update.NodeType == ExpressionType.Lambda)
                {
                    var fieldsContext = new TableBuilder.TableContext(builder, new SelectQuery(), insertStatement.Insert.Into);
                    UpdateBuilder.ParseSet(
                        builder,
                        buildInfo,
                        extract,
                        (LambdaExpression)update,
                        fieldsContext,
                        sequence,
                        insertStatement.Insert.Into,
                        insertStatement.Insert.Items);
                }
                else
                {
                    UpdateBuilder.ParseSet(
                        builder,
                        extract,
                        methodCall,
                        2,
                        sequence,
                        insertStatement.Insert.Items);
                }

                insertStatement.Insert.Items.RemoveDuplicatesFromTail((s1, s2) => s1.Column.Equals(s2.Column));

                return(sequence);
            }
Ejemplo n.º 2
0
            protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
            {
                var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));
                var extract  = (LambdaExpression)methodCall.Arguments[1].Unwrap();
                var update   = methodCall.Arguments[2].Unwrap();

                if (!(sequence.Statement is SqlInsertStatement insertStatement))
                {
                    insertStatement    = new SqlInsertStatement(sequence.SelectQuery);
                    sequence.Statement = insertStatement;
                }

                if (insertStatement.Insert.Into == null)
                {
                    insertStatement.Insert.Into = (SqlTable)sequence.SelectQuery.From.Tables[0].Source;
                    insertStatement.SelectQuery.From.Tables.Clear();
                }

                if (update.NodeType == ExpressionType.Lambda)
                {
                    UpdateBuilder.ParseSet(
                        builder,
                        buildInfo,
                        extract,
                        (LambdaExpression)update,
                        sequence,
                        insertStatement.Insert.Into,
                        insertStatement.Insert.Items);
                }
                else
                {
                    UpdateBuilder.ParseSet(
                        builder,
                        buildInfo,
                        extract,
                        update,
                        sequence,
                        insertStatement.Insert.Items);
                }

                return(sequence);
            }