Udostępnij za pośrednictwem


IS [NOT] OF (Entity SQL)

Determines whether the type of an expression is of the specified type or one of its subtypes.

expression IS [ NOT ] OF ( [ ONLY ] type )

Arguments

  • expression
    Any valid query expression to determine the type of.
  • NOT
    Negates the Boolean result of IS OF.
  • ONLY
    Specifies that IS OF returns true only if expression is of type type and not any of one its subtypes.
  • type
    The type to test expression against. The type must be namespace-qualified.

Return Value

true if expression is of type T and T is either a base type, or a derived type of type; null if expression is null at runtime; otherwise, false.

Remarks

The expressionsexpression IS NOT OF (type)andexpression IS NOT OF (ONLY type)are syntactically equivalent toNOT (expression IS OF (type))and NOT (expression IS OF (ONLY type)), respectively.

The following table shows the behavior of IS OF operator over some typical- and corner patterns. All exceptions are thrown from the client side before the provider gets invoked:

Pattern Behavior

null IS OF (EntityType)

Throws

null IS OF (ComplexType)

Throws

null IS OF (RowType)

Throws

TREAT (null AS EntityType) IS OF (EntityType)

Returns DBNull

TREAT (null AS ComplexType) IS OF (ComplexType)

Throws

TREAT (null AS RowType) IS OF (RowType)

Throws

EntityType IS OF (EntityType)

Returns true/false

ComplexType IS OF (ComplexType)

Throws

RowType IS OF (RowType)

Throws

Example

The following Entity SQL query uses the IS OF operator to determine the type of a query expression, and then uses the TREAT operator to convert an object of the type People to a collection of objects of the type Student. The query is based on the School Entity Data Model. For information about how to generate this model, see Generating the School Entity Data Model (Entity Framework Quickstart).

SELECT VALUE TREAT (people as SchoolDataLib.Student) 
    FROM SchoolDataEntities.People as people 
    WHERE people IS OF( SchoolDataLib.Student)

This example produces the following output:

Chow
Haas
Hamilton
Adams
Paschke
Abrus
Hance

See Also

Concepts

Entity SQL Reference

Other Resources

Type Operators