Share via


where ("M" Reference)

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

The where keyword is used to test members of a collection for a logical condition. It returns a collection of elements that consists of all elements in the original collection that matched the logical condition.

Syntax

Collection whereLogicalExpression

LogicalExpression is any expression that can be evaluated to true or false.

Discussion

The where keyword takes a collection on the left and a logical expression on the right. It introduces a keyword identifier value into the scope of the logical expression that is bound to each member of the collection. When dealing with a collection of collections, the keyword identifier item is also introduced. item is used to access members within the collection elements. The collection that results from the query contains the members for which the expression is true.

Consider the following expression.

Collection where Expression

The preceding expression is exactly equivalent to the following.

from value in Collection
where Expression
select value

Example

The following example shows a function that iterates through the Numbers collection and returns a collection that contains all elements of Numbers that are less than 5.

module Example 
{
    Numbers : Integer32* { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0}
    
    LowNumbers() 
    { 
        from n in Numbers
        where n < 5
        select n
    }
}