CREATEREF (Entity SQL)
Fabricates references to an entity in an entityset.
CreateRef(entityset_identifier, row_typed_expression)
Arguments
- entityset_identifier
The entityset identifier, not a string literal.
- row_typed_expression
A row-typed expression that corresponds to the key properties of the entity type.
Remarks
row_typed_expression must be structurally equivalent to the key type for the entity. That is, it must have the same number and types of fields in the same order as the entity keys.
In the example below, Orders and BadOrders are both entitysets of type Order, and Id is assumed to be the single key property of Order. The example illustrates how we may produce a reference to an entity in BadOrders. Note that the reference may be dangling. That is, the reference may not actually identify a specific entity. In those cases, a DEREF operation on that reference returns a null.
select CreateRef(LOB.BadOrders, row(o.Id))
from LOB.Orders as o
Example
The following Entity SQL query uses the CREATEREF operator to fabricate references to an entity in an entity set. 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 Key(CreateRef(AdventureWorksEntities.Product,
row(p.ProductID))) FROM AdventureWorksEntities.Product as p
The output is shown below:
ProductID: 980
ProductID: 365
ProductID: 771
ProductID: 404
ProductID: 977
...
See Also
Reference
DEREF (Entity SQL)
KEY (Entity SQL)
REF (Entity SQL)