Condividi tramite


ANYELEMENT (Entity SQL)

Extracts an element from a multivalued collection.

ANYELEMENT ( expression )

Arguments

  • expression
    Any valid query expression that returns a collection to extract an element from.

Return Value

A single element in the collection or an arbitrary element if the collection has more than one; if the collection is empty, returns null. If collection is a collection of type Collection<T>, thenANYELEMENT(collection)is a valid expression that yields an instance of type T.

Remarks

ANYELEMENT extracts an arbitrary element from a multivalued collection. For example, the following example attempts to extract a singleton element from the set Customers.

ELEMENT(Customers)

Example

The following Entity SQL query uses the ANYELEMENT operator to extract an element from a multivalued collection. 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 (EntityClient).

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

anyelement((SELECT VALUE product from AdventureWorksEntities.Product as
                        product where product.ListPrice = 125))

The output is shown below:

ProductID: 842
Name: Touring-Panniers, Large
ProductNumber: PA-T100
MakeFlag: False
...

See Also

Concepts

Entity SQL Reference
Nullable Structured Types (Entity SQL)

Other Resources

Set Operators