Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / CommandTrees / DbUpdateCommandTree.cs
1 //---------------------------------------------------------------------
2 // <copyright file="DbUpdateCommandTree.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft, Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections.Generic;
12
13 using System.Data.Metadata.Edm;
14 using System.Data.Common.CommandTrees.Internal;
15 using System.Data.Common.Utils;
16 using System.Diagnostics;
17
18 using ReadOnlyModificationClauses = System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.CommandTrees.DbModificationClause>;  // System.Data.Common.ReadOnlyCollection conflicts
19
20 namespace System.Data.Common.CommandTrees
21 {
22     /// <summary>
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.
26     /// </summary>
27     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
28     public sealed class DbUpdateCommandTree : DbModificationCommandTree
29     {
30         private readonly DbExpression _predicate;
31         private readonly DbExpression _returning;
32         private readonly ReadOnlyModificationClauses _setClauses;
33
34         internal DbUpdateCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning)
35             : base(metadata, dataSpace, target)
36         {
37             EntityUtil.CheckArgumentNull(predicate, "predicate");
38             EntityUtil.CheckArgumentNull(setClauses, "setClauses");
39             // returning is allowed to be null
40
41             this._predicate = predicate;
42             this._setClauses = setClauses;
43             this._returning = returning;
44         }
45
46         /// <summary>
47         /// Gets the list of update set clauses that define the update operation.
48         /// </summary>
49         public IList<DbModificationClause> SetClauses
50         {
51             get
52             {
53                 return _setClauses;
54             }
55         }
56
57         /// <summary>
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.
60         /// </summary>
61         /// <remarks>
62         /// The returning projection includes only the following elements:
63         /// <list>
64         /// <item>NewInstance expression</item>
65         /// <item>Property expression</item>
66         /// </list>
67         /// </remarks>
68         public DbExpression Returning
69         {
70             get
71             {
72                 return _returning;
73             }
74         }
75
76         /// <summary>
77         /// Gets an <see cref="DbExpression"/> that specifies the predicate used to determine which members of the target collection should be updated.
78         /// </summary>
79         /// <remarks>
80         /// The predicate includes only the following elements:
81         /// <list>
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>
90         /// </list>
91         /// </remarks>
92         public DbExpression Predicate
93         {
94             get
95             {   
96                 return _predicate;
97             }
98         }
99
100         internal override DbCommandTreeKind CommandTreeKind
101         {
102             get { return DbCommandTreeKind.Update; }
103         }
104
105         internal override bool HasReader
106         {
107             get { return null != Returning; }
108         }
109
110         internal override void DumpStructure(ExpressionDumper dumper)
111         {
112             base.DumpStructure(dumper);
113
114             if (this.Predicate != null)
115             {
116                 dumper.Dump(this.Predicate, "Predicate");
117             }
118
119             dumper.Begin("SetClauses", null);
120             foreach (DbModificationClause clause in this.SetClauses)
121             {
122                 if (null != clause)
123                 {
124                     clause.DumpStructure(dumper);
125                 }
126             }
127             dumper.End("SetClauses");
128
129             dumper.Dump(this.Returning, "Returning");
130         }
131
132         internal override string PrintTree(ExpressionPrinter printer)
133         {
134             return printer.Print(this);
135         }
136     }
137 }