1 //---------------------------------------------------------------------
2 // <copyright file="DbFunctionCommandTree.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
13 using System.Data.Metadata.Edm;
14 using System.Data.Common.CommandTrees.Internal;
17 namespace System.Data.Common.CommandTrees
21 /// Represents a function invocation expressed as a canonical command tree
23 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
24 public sealed class DbFunctionCommandTree : DbCommandTree
26 private readonly EdmFunction _edmFunction;
27 private readonly TypeUsage _resultType;
28 private readonly System.Collections.ObjectModel.ReadOnlyCollection<string> _parameterNames;
29 private readonly System.Collections.ObjectModel.ReadOnlyCollection<TypeUsage> _parameterTypes;
32 /// Constructs a new DbFunctionCommandTree that uses the specified metadata workspace, data space and function metadata
34 /// <param name="metadata">The metadata workspace that the command tree should use.</param>
35 /// <param name="dataSpace">The logical 'space' that metadata in the expressions used in this command tree must belong to.</param>
36 /// <param name="edmFunction"></param>
37 /// <param name="resultType"></param>
38 /// <param name="parameters"></param>
39 /// <exception cref="ArgumentNullException"><paramref name="metadata"/>, <paramref name="dataSpace"/> or <paramref name="edmFunction"/> is null</exception>
40 /// <exception cref="ArgumentException"><paramref name="dataSpace"/> does not represent a valid data space or
41 /// <paramref name="edmFunction">is a composable function</paramref></exception>
42 /*CQT_PUBLIC_API(*/internal/*)*/ DbFunctionCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, EdmFunction edmFunction, TypeUsage resultType, IEnumerable<KeyValuePair<string, TypeUsage>> parameters)
43 : base(metadata, dataSpace)
45 EntityUtil.CheckArgumentNull(edmFunction, "edmFunction");
47 _edmFunction = edmFunction;
48 _resultType = resultType;
50 List<string> paramNames = new List<string>();
51 List<TypeUsage> paramTypes = new List<TypeUsage>();
52 if (parameters != null)
54 foreach (KeyValuePair<string, TypeUsage> paramInfo in parameters)
56 paramNames.Add(paramInfo.Key);
57 paramTypes.Add(paramInfo.Value);
61 _parameterNames = paramNames.AsReadOnly();
62 _parameterTypes = paramTypes.AsReadOnly();
66 /// Gets the <see cref="EdmFunction"/> that represents the function to invoke
68 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
69 public EdmFunction EdmFunction
78 /// Gets the result type of the function; currently constrained to be a Collection of
79 /// RowTypes. Unlike typical RowType instance, merely indicates name/type not parameter
82 public TypeUsage ResultType
90 internal override DbCommandTreeKind CommandTreeKind
92 get { return DbCommandTreeKind.Function; }
95 internal override IEnumerable<KeyValuePair<string, TypeUsage>> GetParameters()
97 for (int idx = 0; idx < this._parameterNames.Count; idx++)
99 yield return new KeyValuePair<string, TypeUsage>(this._parameterNames[idx], this._parameterTypes[idx]);
103 internal override void DumpStructure(ExpressionDumper dumper)
105 if (this.EdmFunction != null)
107 dumper.Dump(this.EdmFunction);
111 internal override string PrintTree(ExpressionPrinter printer)
113 return printer.Print(this);