1 //---------------------------------------------------------------------
2 // <copyright file="DbInsertCommandTree.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;
17 using System.Collections.ObjectModel;
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 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.
27 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
28 public sealed class DbInsertCommandTree : DbModificationCommandTree
30 private readonly ReadOnlyModificationClauses _setClauses;
31 private readonly DbExpression _returning;
33 internal DbInsertCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning)
34 : base(metadata, dataSpace, target)
36 EntityUtil.CheckArgumentNull(setClauses, "setClauses");
37 // returning may be null
39 this._setClauses = setClauses;
40 this._returning = returning;
44 /// Gets set clauses determining values of columns in the inserted row.
46 public IList<DbModificationClause> SetClauses
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.
59 /// The returning projection includes only the following elements:
61 /// <item>NewInstance expression</item>
62 /// <item>Property expression</item>
65 public DbExpression Returning
73 internal override DbCommandTreeKind CommandTreeKind
75 get { return DbCommandTreeKind.Insert; }
78 internal override bool HasReader
80 get { return null != Returning; }
83 internal override void DumpStructure(ExpressionDumper dumper)
85 base.DumpStructure(dumper);
87 dumper.Begin("SetClauses");
88 foreach (DbModificationClause clause in this.SetClauses)
92 clause.DumpStructure(dumper);
95 dumper.End("SetClauses");
97 if (null != this.Returning)
99 dumper.Dump(this.Returning, "Returning");
103 internal override string PrintTree(ExpressionPrinter printer)
105 return printer.Print(this);