Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / CommandTrees / DbInsertCommandTree.cs
1 //---------------------------------------------------------------------
2 // <copyright file="DbInsertCommandTree.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 using System.Collections.ObjectModel;
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 insert 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 value indicating the number of rows affected.
26     /// </summary>
27     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
28     public sealed class DbInsertCommandTree : DbModificationCommandTree
29     {
30         private readonly ReadOnlyModificationClauses _setClauses;
31         private readonly DbExpression _returning;
32
33         internal DbInsertCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning)
34             : base(metadata, dataSpace, target)
35         {
36             EntityUtil.CheckArgumentNull(setClauses, "setClauses");
37             // returning may be null
38
39             this._setClauses = setClauses;
40             this._returning = returning;
41         }
42
43         /// <summary>
44         /// Gets set clauses determining values of columns in the inserted row.
45         /// </summary>
46         public IList<DbModificationClause> SetClauses 
47         {
48             get 
49             {
50                 return _setClauses; 
51             }
52         }
53
54         /// <summary>
55         /// Gets an <see cref="DbExpression"/> that specifies a projection of results to be returned based on the modified rows.
56         /// If null, indicates no results should be returned from this command.
57         /// </summary>
58         /// <remarks>
59         /// The returning projection includes only the following elements:
60         /// <list>
61         /// <item>NewInstance expression</item>
62         /// <item>Property expression</item>
63         /// </list>
64         /// </remarks>
65         public DbExpression Returning
66         {
67             get
68             {
69                 return _returning;
70             }
71         }
72
73         internal override DbCommandTreeKind CommandTreeKind
74         {
75             get { return DbCommandTreeKind.Insert; }
76         }
77
78         internal override bool HasReader
79         {
80             get { return null != Returning; }
81         }
82
83         internal override void DumpStructure(ExpressionDumper dumper)
84         {
85             base.DumpStructure(dumper);
86
87             dumper.Begin("SetClauses");
88             foreach (DbModificationClause clause in this.SetClauses)
89             {
90                 if (null != clause)
91                 {
92                     clause.DumpStructure(dumper);
93                 }
94             }
95             dumper.End("SetClauses");
96
97             if (null != this.Returning)
98             {
99                 dumper.Dump(this.Returning, "Returning");
100             }
101         }
102
103         internal override string PrintTree(ExpressionPrinter printer)
104         {
105             return printer.Print(this); 
106         }
107     }
108 }