1 //---------------------------------------------------------------------
2 // <copyright file="DbUpdateCommandTree.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // @owner Microsoft, Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
13 using System.Data.Metadata.Edm;
14 using System.Data.Common.CommandTrees.Internal;
15 using System.Data.Common.Utils;
16 using System.Diagnostics;
18 using ReadOnlyModificationClauses = System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.CommandTrees.DbModificationClause>; // System.Data.Common.ReadOnlyCollection conflicts
20 namespace System.Data.Common.CommandTrees
23 /// Represents a single-row update operation expressed as a canonical command tree.
24 /// When the <see cref="Returning"/> property is set, the command returns a reader; otherwise,
25 /// it returns a scalar indicating the number of rows affected.
27 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
28 public sealed class DbUpdateCommandTree : DbModificationCommandTree
30 private readonly DbExpression _predicate;
31 private readonly DbExpression _returning;
32 private readonly ReadOnlyModificationClauses _setClauses;
34 internal DbUpdateCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning)
35 : base(metadata, dataSpace, target)
37 EntityUtil.CheckArgumentNull(predicate, "predicate");
38 EntityUtil.CheckArgumentNull(setClauses, "setClauses");
39 // returning is allowed to be null
41 this._predicate = predicate;
42 this._setClauses = setClauses;
43 this._returning = returning;
47 /// Gets the list of update set clauses that define the update operation.
49 public IList<DbModificationClause> SetClauses
58 /// Gets an <see cref="DbExpression"/> that specifies a projection of results to be returned based on the modified rows.
59 /// If null, indicates no results should be returned from this command.
62 /// The returning projection includes only the following elements:
64 /// <item>NewInstance expression</item>
65 /// <item>Property expression</item>
68 public DbExpression Returning
77 /// Gets an <see cref="DbExpression"/> that specifies the predicate used to determine which members of the target collection should be updated.
80 /// The predicate includes only the following elements:
82 /// <item>Equality expression</item>
83 /// <item>Constant expression</item>
84 /// <item>IsNull expression</item>
85 /// <item>Property expression</item>
86 /// <item>Reference expression to the target</item>
87 /// <item>And expression</item>
88 /// <item>Or expression</item>
89 /// <item>Not expression</item>
92 public DbExpression Predicate
100 internal override DbCommandTreeKind CommandTreeKind
102 get { return DbCommandTreeKind.Update; }
105 internal override bool HasReader
107 get { return null != Returning; }
110 internal override void DumpStructure(ExpressionDumper dumper)
112 base.DumpStructure(dumper);
114 if (this.Predicate != null)
116 dumper.Dump(this.Predicate, "Predicate");
119 dumper.Begin("SetClauses", null);
120 foreach (DbModificationClause clause in this.SetClauses)
124 clause.DumpStructure(dumper);
127 dumper.End("SetClauses");
129 dumper.Dump(this.Returning, "Returning");
132 internal override string PrintTree(ExpressionPrinter printer)
134 return printer.Print(this);