# CREATEREF (Entity SQL)

Fabricates references to an entity in an entityset.

## Syntax

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:

1. Follow the procedure in How to: Execute a Query that Returns StructuralType Results.

2. Pass the following query as an argument to the ExecuteStructuralTypeQuery method:

SELECT VALUE Key(CreateRef(AdventureWorksEntities.Products,
row(p.ProductID)))