b129bb2efe035aac35d93f9bdb746a74ffced150
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / CommandTrees / DbModificationCommandTree.cs
1 //---------------------------------------------------------------------
2 // <copyright file="DbModificationCommandTree.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.Linq;
17
18 namespace System.Data.Common.CommandTrees
19 {
20     /// <summary>
21     /// Represents a DML operation expressed as a canonical command tree
22     /// </summary>
23     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
24     public abstract class DbModificationCommandTree : DbCommandTree
25     {
26         private readonly DbExpressionBinding _target;
27         private System.Collections.ObjectModel.ReadOnlyCollection<DbParameterReferenceExpression> _parameters;
28
29         internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target)
30             : base(metadata, dataSpace)
31         {
32             EntityUtil.CheckArgumentNull(target, "target");
33
34             this._target = target;
35         }
36
37         /// <summary>
38         /// Gets the <see cref="DbExpressionBinding"/> that specifies the target table for the DML operation.
39         /// </summary>
40         public DbExpressionBinding Target
41         {
42             get
43             {
44                 return _target;
45             }
46         }
47
48         /// <summary>
49         /// Returns true if this modification command returns a reader (for instance, to return server generated values)
50         /// </summary>
51         internal abstract bool HasReader
52         {
53             get;
54         }
55
56         internal override IEnumerable<KeyValuePair<string, TypeUsage>> GetParameters()
57         {
58             if (this._parameters == null)
59             {
60                 this._parameters = ParameterRetriever.GetParameters(this);
61             }
62             return this._parameters.Select(p => new KeyValuePair<string, TypeUsage>(p.ParameterName, p.ResultType));
63         }
64
65         internal override void DumpStructure(ExpressionDumper dumper)
66         {
67             if (this.Target != null)
68             {
69                 dumper.Dump(this.Target, "Target");
70             }
71         }
72     }
73 }