Muokkaa

Jaa


UNION (Entity SQL)

Combines the results of two or more queries into a single collection.

Syntax

expression
UNION [ ALL ]
expression

Arguments

expression Any valid query expression that returns a collection to combine with the collection All expressions must be of the same type or of a common base or derived type as expression.

UNION Specifies that multiple collections are to be combined and returned as a single collection.

ALL Specifies that multiple collections are to be combined and returned as a single collection, including duplicates. If not specified, duplicates are removed from the result collection.

Return Value

A collection of the same type or of a common base or derived type as expression.

Remarks

UNION is one of the Entity SQL set operators. All Entity SQL set operators are evaluated from left to right. For precedence information for the Entity SQL set operators, see EXCEPT.

Example

The following Entity SQL query uses the UNION ALL operator to combine the results of two queries into a single 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.

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

(SELECT VALUE P FROM AdventureWorksEntities.Products 
    AS P WHERE P.Name LIKE 'C%') UNION ALL 
    (SELECT VALUE A FROM AdventureWorksEntities.Products 
    AS A WHERE A.ListPrice > @price)

See also