private void BuildUpdateAction(MergeSpecification specification)
        {
            var clause     = new MergeActionClause();
            var expression =
                (clause.SearchCondition = new BooleanParenthesisExpression()) as BooleanParenthesisExpression;

            var isNulls = BuildNullIfStatements();

            if (isNulls.Count > 1)
            {
                var expressions = CreateExpressionTreeForUpdateSearch(isNulls);

                //Save the first expression
                expression.Expression  = expressions.First();
                clause.SearchCondition = expression;
            }
            else
            {
                clause.SearchCondition = isNulls[0];
            }
            clause.Condition = MergeCondition.Matched;
            clause.Action    = CreateUpdateSetActions(clause);

            specification.ActionClauses.Add(clause);
        }
Beispiel #2
0
        private UpdateMergeAction CreateUpdateSetActions(MergeActionClause clause)
        {
            var action = (clause.Action = new UpdateMergeAction()) as UpdateMergeAction;

            foreach (var col in _merge.Table.Columns)
            {
                var setClause = new AssignmentSetClause();
                setClause.AssignmentKind = AssignmentKind.Equals;

                var identifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.TargetName, col.Name.GetName());

                setClause.Column = new ColumnReferenceExpression();
                setClause.Column.MultiPartIdentifier = identifier;

                var newValue = (setClause.NewValue = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                newValue.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, col.Name.GetName());

                action.SetClauses.Add(setClause);
            }
            return(action);
        }
Beispiel #3
0
 public override void Visit(MergeActionClause node) { this.action(node); }
 public override void ExplicitVisit(MergeActionClause fragment)
 {
     _fragments.Add(fragment);
 }
Beispiel #5
0
        private UpdateMergeAction CreateUpdateSetActions(MergeActionClause clause)
        {
            var action = (clause.Action = new UpdateMergeAction()) as UpdateMergeAction;
            foreach (var col in _merge.Table.Columns)
            {
                var setClause = new AssignmentSetClause();
                setClause.AssignmentKind = AssignmentKind.Equals;

                var identifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.TargetName, col.Name.GetName());

                setClause.Column = new ColumnReferenceExpression();
                setClause.Column.MultiPartIdentifier = identifier;

                var newValue = (setClause.NewValue = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                newValue.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, col.Name.GetName());
                
                action.SetClauses.Add(setClause);
            }
            return action;
        }
Beispiel #6
0
        private void BuildUpdateAction(MergeSpecification specification)
        {
            var clause = new MergeActionClause();
            var expression =
                (clause.SearchCondition = new BooleanParenthesisExpression()) as BooleanParenthesisExpression;

            var isNulls = BuildNullIfStatements();

            if (isNulls.Count > 1)
            {
                var expressions = CreateExpressionTreeForUpdateSearch(isNulls);

                //Save the first expression
                expression.Expression = expressions.First();
                clause.SearchCondition = expression;
            }
            else
            {
                clause.SearchCondition = isNulls[0];
            }
            clause.Condition = MergeCondition.Matched;
            clause.Action = CreateUpdateSetActions(clause);

            specification.ActionClauses.Add(clause);
        }