确定表达式的类型是指定类型还是其子类型之一。
语法
expression IS [ NOT ] OF ( [ ONLY ] type )
论据
expression
用于确定其类型的任何有效查询表达式。
不否定 EDM。IS OF 的布尔结果。
仅指定 IS OF 仅当类型type
不是其任何子类型时才expression
返回true
。
type
要测试 expression
的类型。 类型必须是命名空间限定的。
返回值
true
如果 expression
类型为 T 且 T 为基类型,则为派生类型 type
;如果 expression
运行时为 null,则为 null;否则为 false
。
注解
表达式 expression IS NOT OF (type)
和 expression IS NOT OF (ONLY type)
语法分别等效 NOT (expression IS OF (type))
于和 NOT (expression IS OF (ONLY type))
。
下表显示了运算符在某些典型模式和角模式上的行为 IS OF
。 在调用提供程序之前,会从客户端引发所有异常:
图案 | 行为 |
---|---|
null IS OF (EntityType) | Throws |
null IS OF (ComplexType) | Throws |
null IS OF (RowType) | Throws |
TREAT (NULL AS EntityType) IS OF (EntityType) | 返回 DBNull |
TREAT (NULL AS ComplexType) IS OF (ComplexType) | Throws |
TREAT (NULL AS RowType) IS OF (RowType) | Throws |
EntityType IS OF (EntityType) | 返回 true/false |
ComplexType IS OF (ComplexType) | Throws |
RowType IS OF (RowType) | Throws |
示例:
以下 Entity SQL 查询使用 IS OF 运算符来确定查询表达式的类型,然后使用 TREAT 运算符将类型 Course 的对象转换为 OnsiteCourse 类型的对象的集合。 查询基于 学校模型。
[!code-sql[DP EntityServices Concepts#TREAT_ISOF]~/samples/snippets/tsql/VS_Snippets_Data/dp entityservices concepts/tsql/entitysql.sql#treat_isof]]