Send feedback on this topic.
Teradata.Client.Provider
Entity Provider Function Import Support
.NET Data Provider for Teradata > Developer's Guide > ADO.NET Entity Provider for Teradata > Teradata Implementation Specifics > Working with Parameters in the Entity Provider > Entity Provider Function Import Support
.NET CORE   This feature is not supported by the .NET Core implementation of the Data Provider.

When a Teradata Stored Procedure is imported into the model, the Visual Studio Entity Data Model Wizard does not persist some facets of a function parameter such as MaxLength, Precision, Scale for the function imported to the SSDL file. This may have an impact in the execution of the function and its results. The following sections describe the changes that are required for an Input and Input Output parameter. Output parameters do not require any change to the SSDL file. Also we recommend using separate Input and Output parameter in-place of an Input Output parameter wherever possible.

A Facet provides additional Data Type information. For example

  1. MaxLength facet can describe the maximum number of characters for a VarChar Stored Procedure parameter.
  2. Precision facet can describe the maximum number of digits for a Decimal Stored Procedure parameter.
  3. Scale facet can describe the maximum number sub-second digits for a TimeStamp Stored Procedure parameter.

Input Function Parameters

Whenever possible the Entity Provider will infer the Facet value from the Data or it will assign a compatible Facet value to the Function Parameter. The table below describes the inferred or assigned facet values for Input parameters of affected Data Types:

Teradata Data Type SSDL Type Name
(Case Sensitive)
.NET Data Type Facet Name Facet
Minimum
value
Facet
Maximum
Value
Inferred or Assigned
Facet Value
Blob blob System.Byte[] MaxLength 1 2,097,088,000 The Entity Provider sets the maximum length to 2,097,088,000 when the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Byte byte System.Byte[] MaxLength 1 64,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
Decimal decimal System.Decimal Precision 1 38 The Entity Provider calculates the precision and scale from the parameter value when the Precision or scale facet is not explicitly specified.
Scale 0 38
Number number System.Double Precision 1 38 The Entity Provider calculates the precision and scale from the parameter value when the Precision or scale facet is not explicitly specified.
Scale 0 38
Interval Day interval day System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Day To Hour interval day to hour System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Day To Minute interval day to minute System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Hour interval hour System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Hour To Minute interval hour to minute System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Minute interval minute System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision from the parameter value.
Interval Day To Second interval day to second System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision and scale from the parameter value.
Scale 0 6
Interval Hour To Second interval hour to second System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision and scale from the parameter value.
Scale 0 6
Interval Minute To Second interval minute to second System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision and scale from the parameter value.
Scale 0 6
Interval Second interval second System.TimeSpan Precision 1 4 The Entity Provider always calculates the precision and scale from the parameter value.
Scale 0 6
Char char System.String MaxLength 1 64,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
Clob clob System.String MaxLength 1 2,097,088,000 The Entity Provider sets the maximum length to 2,097,088,000 when the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Graphic graphic System.String MaxLength 1 32,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
Interval Month interval month System.String MaxLength 2 5 The Entity Provider always calculates the MaxLength from the parameter value.
Interval Year interval year System.String MaxLength 2 5 The Entity Provider always calculates the MaxLength from the parameter value.
Interval Year To Month interval year to month System.String MaxLength 5 8 The Entity Provider always calculates the MaxLength from the parameter value.
Period Date period date System.String MaxLength 20 20 The Entity Provider always calculates the MaxLength from the parameter value.
Period Time period time System.String MaxLength 20 34 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified. If MaxLength facet is specified and if the length does not match the function definition, The Advanced SQL Engine throws the following "Invalid input data for period. The input data precision must not be greater than the described precision" exception.

Recommendation: Do not specify a MaxLength facet to the SSDL file and let the Entity Provider calculate the length from the parameter value.
Period Timestamp period timestamp System.String MaxLength 42 56 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified. If MaxLength facet is specified and if the length does not match the function definition, the SQL Engine throws the following "Invalid input data for period. The input data precision must not be greater than the described precision" exception.

Recommendation: Do not specify a MaxLength facet to the SSDL file and let the Entity Provider calculate the length from the parameter value.
Period Timestamp With Time Zone period timestamp with time zone System.String MaxLength 54 68 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified. If MaxLength facet is specified and if the length does not match the function definition, the SQL Engine throws the following "Invalid input data for period. The input data precision must not be greater than the described precision" exception.

Recommendation: Do not specify a MaxLength facet to the SSDL file and let the Entity Provider calculate the length from the parameter value.
Period Time With Time Zone period time with time zone System.String MaxLength 32 46 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified. If MaxLength facet is specified and if the length does not match the function definition, the SQL Engine throws the following "Invalid input data for period. The input data precision must not be greater than the described precision" exception.

Recommendation: Do not specify a MaxLength facet to the SSDL file and let the Entity Provider calculate the length from the parameter value.
Time time System.Timespan Precision 0 6 The Entity Provider sets the Precision to zero when the Precision facet is not explicitly specified. The Data Provider will truncate the sub-second digits.

Recommendation: Manually add the Precision facet to the SSDL file.
Timestamp timestamp System.DateTime Precision 0 6 The Entity Provider sets the Precision to zero when the Precision facet is not explicitly specified. The Data Provider will truncate the sub-second digits.

Recommendation: Manually add the Precision facet to the SSDL file.
Timestamp With Time Zone timestamp with time zone System.DateTimeOffset Precision 0 6 The Entity Provider sets the Precision to zero when the Precision facet is not explicitly specified. The Data Provider will truncate the sub-second digits.

Recommendation: Manually add the Precision facet to the SSDL file.
Time With Time Zone time with time zone System.String MaxLength 14 21 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
VarByte varbyte System.Byte[] MaxLength 1 64,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
VarChar varchar System.String MaxLength 1 64,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
VarGraphic vargraphic System.String MaxLength 1 32,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
Xml xml System.String MaxLength 1 2,097,088,000 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.
JSON json System.String MaxLength 1 16,776,192 The Entity Provider calculates the maximum length from the parameter value when the MaxLength facet is not explicitly specified.

Input Output Function Parameters

The ObjectParameter that is created for specifying an Input Output parameter can be of .NET Data Type or Provider specific type (if applicable for the datatype). Please note that when a Provider Specific type is used to declare an Input Output parameter, the user can pass a Provider Specific value as Input but the output object will be of .NET Data type only. The table below describes the issues that might be seen with Input Output parameters and how they can be resolved with .NET Data type or Provider Specific type.

Teradata Data Type SSDL Type Name
(Case Sensitive)
.NET Data Type

vs.

Provider Specific Type
Facet Name Facet
Minimum
value
Facet
Maximum
Value
Inferred or Assigned
Facet Value
Byte byte System.Byte[] MaxLength 1 64,000 The Data Provider will throw an exception if the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
VarByte varbyte System.Byte[] MaxLength 1 64,000 The Data Provider will throw an exception if the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Char char System.String MaxLength 1 64,000 The Data Provider will throw an exception if the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
VarChar varchar System.String MaxLength 1 64,000 The Data Provider will throw an exception if the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Blob blob System.Byte[]



TdBlob
MaxLength 1 2,097,088,000 The Entity Provider sets the maximum length to 2,097,088,000 when the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Clob clob System.String



TdClob
MaxLength 1 2,097,088,000 The Entity Provider sets the maximum length to 2,097,088,000 when the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.
Number number System.Double

TdNumber
Precision 1 38 The Entity Provider calculates the precision and scale from the parameter value when the Precision or scale facet is not explicitly specified.
Scale 0 38
Decimal decimal System.Decimal

TdDecimal
Precision 1 38 The Entity Provider calculates the precision and scale from the parameter value when the Precision or scale facet is not explicitly specified.
Scale 0 38
Interval Day interval day System.TimeSpan



TdIntervalDay
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Day To Hour interval day to hour System.TimeSpan



TdIntervalDayToHour
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Day To Minute interval day to minute System.TimeSpan



TdIntervalDayToMinute
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Hour interval hour System.TimeSpan



TdIntervalHour
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Hour To Minute interval hour to minute System.TimeSpan



TdIntervalHourToMinute
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Minute interval minute System.TimeSpan



TdIntervalMinute
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Day To Second interval day to second System.TimeSpan



TdIntervalDayToSecond
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision and/or scale in the input value does not match the function definition. Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision and scale that matches the function definition.
Scale 0 6
Interval Hour To Second interval hour to second System.TimeSpan



TdIntervalHourToSecond
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision and/or scale in the input value does not match the function definition. Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision and scale that matches the function definition.
Scale 0 6
Interval Minute To Second interval minute to second System.TimeSpan



TdIntervalMinuteToSecond
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision and/or scale in the input value does not match the function definition. Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision and scale that matches the function definition.
Scale 0 6
Interval Second interval second System.TimeSpan



TdIntervalSecond
Precision 1 4 If a TimeSpan Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision and/or scale in the input value does not match the function definition. Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision and scale that matches the function definition.
Scale 0 6
Interval Month interval month System.String



TdIntervalMonth
MaxLength



Precision
2



1
5



4
If a String Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. MaxLength, Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Year interval year System.String



TdIntervalYear
MaxLength



Precision
2



1
5



4
If a String Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. MaxLength, Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Interval Year To Month interval year to month System.String



TdIntervalYearToMonth
MaxLength



Precision
5



1
8



4
If a String Object is used, the SQL Engine might throw an Interval field Overflow exception if the precision in the input value does not match the function definition. MaxLength, Precision mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Period Time period time System.String



TdPeriodTime
MaxLength



Precision
20



0
34



6
If a String Object is used, the SQL Engine might throw an Invalid conversion or assignment operation on a period exception if the precision and/or scale in the input value does not match the function definition. MaxLength, Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Period Timestamp period timestamp System.String



TdPeriodTimestamp
MaxLength



Precision
42



0
56



6
If a String Object is used, the SQL Engine might throw an Invalid conversion or assignment operation on a period exception if the precision and/or scale in the input value does not match the function definition. MaxLength, Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Period Timestamp With Time Zone period timestamp with time zone System.String



TdPeriodTimestampWithTimeZone
MaxLength



Precision
54



0
68



6
If a String Object is used, the SQL Engine might throw an Invalid conversion or assignment operation on a period exception if the precision and/or scale in the input value does not match the function definition. MaxLength, Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition.
Period Time With Time Zone period time with time zone System.String



TdPeriodTimeWithTimeZone
MaxLength



Precision
32



0
46



6
If a String Object is used, the SQL Engine might throw an Invalid conversion or assignment operation on a period exception if the precision and/or scale in the input value does not match the function definition. MaxLength, Precision and Scale mentioned in the SSDL is not considered.

Recommendation: Use a Provider Specific DataType parameter with correct precision matches the function definition.
Time time System.Timespan



TdTime
Precision 0 6 When Timespan object is used as parameter, the Precision has to be specified in the SSDL. Alternatively a TdTime provider specific type can be created with correct precision that matches the function definition.
Timestamp timestamp System.DateTime



TdTimestamp
Precision 0 6 When DateTime object is used as parameter, the Precision has to be specified in the SSDL. Alternatively a TdTimestamp provider specific type can be created with correct precision that matches the function definition.
Timestamp With Time Zone timestamp with time zone System.DateTimeOffset



TdTimestampWithTimeZone
Precision 0 6 When DateTimeOffset object is used as parameter, the Precision has to be specified in the SSDL. Alternatively a TdTimestampWithTimeZone provider specific type can be created with correct precision that matches the function definition.
Time With Time Zone time with time zone System.String



TdTimeWithTimeZone
MaxLength



Precision
14



0
21



6
If a String Object is used, the SQL Engine might throw an DateTime Overflow exception if the precision in the input value does not match the function definition.

Recommendation: Use a Provider Specific DataType parameter with correct precision that matches the function definition or specify the precision in the SSDL
Xml xml System.String

TdXml
MaxLength 1 2,097,088,000 The Data Provider will calculate the length from the parameter value if the MaxLength facet is not specified in the SSDL.
JSON json System.String MaxLength 1 16,776,192 The Data Provider will throw an exception if the MaxLength facet is not explicitly specified.

Recommendation: Manually add the MaxLength facet to the SSDL file.

The SSDL must be manually modified to include correct MaxLength, Precision, and Scale facets values for a Function parameter where relevant as described above. For Input parameters, we recommend changes to Time, Timestamp, Timestamp With Time Zone, BLOB and CLOB data types (see table for Input parameters). Also whenever possible, we recommend using separate Input and Output parameter instead of using a single Input Output parameter.

Here is an example of a generated and modified Function element in the SSDL.

Generated
Copy Code
<Function Name="BranchInsert" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false"
          ParameterTypeSemantics="AllowImplicitConversion" Schema="CarRentalModel">
    <Parameter Name="Branchid" Type="integer" Mode="In" />
    <Parameter Name="Opentime" Type="timestamp" Mode="In"  />
</Function>
Modified
Copy Code
<Function Name="BranchInsert" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false"
          ParameterTypeSemantics="AllowImplicitConversion" Schema="CarRentalModel">
      <Parameter Name="Branchid" Type="integer" Mode="In" />
      <Parameter Name="Opentime" Type="timestamp" Mode="In" Precision="2" />
</Function>

ADO.NET Entity Data Model Designer allows storage model editing in the XML Editor. However, any update to the model with the Update Wizard will discard all manual changes made to the storage model.

The SQL Engine does not return Stored Procedure result-set metadata. Hence, an imported function, will not have a return type or collection associated with it. After the function is imported into the model, a user can bring up the Add or Edit Function Import wizard from Model Browser and change the return type as required.

Visual Studio code generation is supported for Function Imports only for stored procedures that return a collection of an EntityType when the target framework is .NET Framework 3.5. And, the columns returned by the corresponding stored procedures must exactly match the properties of the returned EntityType. If the method should return nothing or a collection of scalars, the target framework has to be .NET Framework 4.0 or above for the code generation to work.

In the example below, the stored procedure returns the unit price of a product by the product id it gets as a parameter.

Example
Copy Code
CREATE PROCEDURE GetUnitPriceForProduct(in pId integer)
DYNAMIC RESULT SETS 1
BEGIN
    declare cur1 cursor with return only to client for
    Select UnitPrice From Product Where ProductID = :pId;
    open cur1;
END;

Step 1: Add a FunctionImport for the stored procedure.
In the designer press the right mouse button and click on the Add -> Function Import from the menu. The Add Function Import dialog will be open and insert the following details:

Press OK to end this process. After step 1, the FunctionImport element will be added to the CSDL. However, it cannot be used from the object context because no code will be generated for it.

Step 2: Use EntityClient to query the data. The following code shows how to open a connection, create a stored procedure command, add parameters to it and execute it using EntityClient.

EDM Example
Copy Code
static void Main(string[] args)
{
    decimal result = 0;
    using (var conn = new EntityConnection("Name = EDMExample"))
    {
         var cmd = conn.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "EDMExample.GetUnitPriceForProduct";
         cmd.Parameters.AddWithValue("pId", 1);
         conn.Open();
         result = Convert.ToDecimal(cmd.ExecuteScalar());
    }
    Console.WriteLine("Total = {0}", result);
}