Edm.Time maps to Time and several Interval Teradata types. When the data of a parameter represents an Interval, the Entity Framework will indicate that the parameter is a EDM.Time. When the Entity Provider is creating a TdParameter it will map parameters that are of type EDM.Time to TdType.Time.
When LINQ to Entities is used in an application the value of the parameter that represents an Interval must be a System.TimeSpan. The Entity Framework will indicate that the parameter is an EDM.Time in the information that is passed to the Entity Provider.
When Entity Sql is used an application, the EntityParameter object can be used to define any parameters contained in Entity Sql statement. The EntityParameter.Value property can either be set to a System.TimeSpan or to the provider specific type for the interval (i.e. TdIntervalDayToSecond, TdIntervalDay, etc..). The EntityParameter.DbType property must also be set to DbType.Time.
The problem that occurs when a parameter represents an Interval is the Entity Provider cannot use the default TdType mapping (TdType.Time) for EDM.Time. The Data Provider for Teradata is unable to convert an Interval to a TdTime. Therefore, if the parameter represents an Interval and the TdType were set to TdType.Time, the Data Provider for Teradata will throw a TdException that indicates that the Interval cannot be converted to a Time.
To solve this problem, the Entity Provider for Teradata performs special processing when the type of a parameter is EDM.Time. This special processing includes determining if the parameter corresponds to an Interval. This is accomplished by inspecting the operands related to the parameter and determining their Teradata Data Type. If the related operands are Intervals, the parameter is also an Interval. Once the Entity Provider determines that the parameter is an Interval it will set the TdParameter.TdType to TdType.IntervalDayToSecond. TdType.IntervalDayToSecond is specified because the Data Provider can convert any Interval that maps to EDM.Time and System.TimeSpan to an Interval Day To Second representation. The Advanced SQL Engine is also able to implicitly convert data represented as an Interval Day To Second to any Interval type that maps to EDM.Time.
The Entity Provider is able to determine the Teradata type of a parameter under the following scenarios:
Comparison Expressions |
Copy Code |
---|---|
// This is a LINQ to Entities example // // String represents an Interval Second TimeSpan interval = TimeSpan.Parse("00:00:10.2123"); // c1IntervalSecond is a Teradata type Interval Second (2, 4) var query = from i in IntervalEntity where i.c1IntervalSecond == interval select i; |
In this example, the Entity Provider will inspect the operand opposite the parameter. The Teradata specific Metadata passed from the Framework to the Entity Provider will indicate that this operand is an Interval Second with a precision (microsecond) value of 4. Based on the metadata of the operand opposite the parameter, the Entity Provider will perform the following:
Case Expression |
Copy Code |
---|---|
// This is an Entity Sql example // // Logon to the SQL Engine has occurred -- eConn is the EntityConnection EntityCommand eCmd = eConn.CreateCommand(); // String represents an Interval Day EntityParameter eParam = new eParam(); eParam.ParameterName = "intervalDay"; eParam.DbType = DbType.Time; eParam.Value = new TdIntervalDay(10); eCmd.Parameters.Add(eParam); eCmd.CommandText = "select i from IntervalEntity as i where " + "where i.c5IntervalDay == (CASE WHEN i.c1 == 10 THEN @intervalDay ELSE i.c10IntervalDay END)" |
In this example, the parameter is contained in the THEN clause of the CASE. The CASE in the Entity Sql statement will generate a CASE in the SQL statement. The Entity Provider will determine the Teradata type that will be returned from the CASE in the SQL statement. In this example it is an interval. Therefore, the TdType is set to TdType.IntervalDayToSecond.
The Entity Framework only allows properties of an entity that has a numeric or string EDM type to be included in an Arithmetic expression. Therefore, a property of EDM.Time cannot be compared against an arithmetic expression or be an operand of an expression.