ROW (Entity SQL)
Constructs anonymous, structurally typed records from one or more values.
ROW ( expression [ AS alias ] [,...] )
Arguments
- expression
Any valid query expression that returns a value to construct in a row type.
- alias
Specifies an alias for the value specified in a row type. If an alias is not provided, Entity SQL tries to generate an alias based on the Entity SQL alias generation rules.
Return Value
A row type.
Remarks
You use row constructors in the Entity SQL to construct anonymous, structurally typed records from one or more values. The result type of a row constructor is a row type whose field types correspond to the types of the values that were used to construct the row. For example, the following expression constructs a value of type Record(a int, b string, c int)
.
ROW(1 AS a, "abc" AS b, a+34 AS c)
If you do not provide an alias for an expression in a row constructor, the Entity Framework will try to generate one. For more information, see the "Aliasing Rules" section of the Identifiers topic.
The following rules apply to expression aliasing in a row constructor:
Expressions in a row constructor cannot refer to other aliases in the same constructor.
Two expressions in the same row constructor cannot have the same alias.
For more information about query constructors, see Constructing Types (Entity SQL).
Example
The following Entity SQL query uses the ROW operator to construct anonymous, structurally typed records. 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 row (product.ProductID as ProductID,
product.Name as ProductName) FROM AdventureWorksEntities.Product
AS product
The output is shown below:
ProductID: 1
ProductName: Adjustable Race
ProductID: 879
ProductName: All-Purpose Bike Stand
ProductID: 712
ProductName: AWC Logo Cap
ProductID: 3
ProductName: BB Ball Bearing
ProductID: 2
ProductName: Bearing Ball
...