Named Type Constructor (Entity SQL)
Used to create instances of Entity Data Model (EDM) nominal types such as Entity or Complex types.
[{identifier. }] identifier( [expression [{, expression }]] )
Arguments
- identifier
Value that is a simple or quoted identifier. For more information see, Identifiers (Entity SQL)
- expression
Attributes of the type that are assumed to be in the same order as they appear in the declaration of the type.
Return Value
Instances of named complex types and entity types.
Remarks
The following examples show how to construct nominal and complex types:
The expression below creates an instance of a Person type:
Person("abc", 12)
The expression below creates an instance of a complex type:
MyModel.ZipCode(‘98118’, ‘4567’)
The expression below creates an instance of a nested complex type:
MyModel.AddressInfo('My street address', 'Seattle', 'WA', MyModel.ZipCode('98118', '4567'))
The expression below creates an instance of an entity with a nested complex type:
MyModel.Person("Bill", MyModel.AddressInfo('My street address', 'Seattle', 'WA', MyModel.ZipCode('98118', '4567')))
The following example shows how to initialize a property of a complex type to null:MyModel.ZipCode(‘98118’, null)
Example
The following Entity SQL query uses the named type constructor to create an instance of an EDM type. The query is based on the AdventureWorks Sales Model. To compile and run this query, follow these steps:
Follow the procedure in How to: Execute a Query that Returns StructuralType Results (EntityClient).
Pass the following query as an argument to the
ExecuteStructuralTypeQuery
method:
SELECT VALUE AdventureWorksModel.SalesOrderDetail
(o.SalesOrderDetailID, o.CarrierTrackingNumber,
o.OrderQty, o.ProductID, o.SpecialOfferID, o.UnitPrice,
o.UnitPriceDiscount, o.rowguid, o.ModifiedDate)
FROM AdventureWorksEntities.SalesOrderDetail AS o
This example produces the following output:
SalesOrderDetailID: 1
CarrierTrackingNumber: 4911-403C-98
OrderQty: 1
ProductID: 776
SalesOrderDetailID: 2
CarrierTrackingNumber: 4911-403C-98
OrderQty: 3
ProductID: 777
SalesOrderDetailID: 3
CarrierTrackingNumber: 4911-403C-98
OrderQty: 1
ProductID: 778
SalesOrderDetailID: 4
CarrierTrackingNumber: 4911-403C-98
OrderQty: 1
ProductID: 771
SalesOrderDetailID: 5
CarrierTrackingNumber: 4911-403C-98
OrderQty: 1
ProductID: 772
...