ISOF (Entity SQL)

确定表达式的类型是否为指定类型或指定类型的某个子类型。

语法

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

参数

expression 用于确定其类型的任何有效查询表达式。

NOT 对 IS OF 的 EDM.Boolean 结果取反。

ONLY 指定仅当 expression 的类型为 type,而不是其任何子类型时,IS OF 才返回 true

type 要针对其测试 expression 的类型。 该类型必须由命名空间进行限定。

返回值

如果 expression 的类型为 T 且 T 为基类型或 type 的派生类型,则返回 true;如果 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) 引发
null IS OF (ComplexType) 引发
null IS OF (RowType) 引发
TREAT (null AS EntityType) IS OF (EntityType) 返回 DBNull。
TREAT (null AS ComplexType) IS OF (ComplexType) 引发
TREAT (null AS RowType) IS OF (RowType) 引发
EntityType IS OF (EntityType) 返回 true/false
ComplexType IS OF (ComplexType) 引发
RowType IS OF (RowType) 引发

示例

下面的实体 SQL 查询使用 IS OF 运算符来确定一个查询表达式的类型,然后使用 TREAT 运算符将一个类型为 Course 的对象转换为类型为 OnsiteCourse 的对象的集合。 该查询基于 School 模型

[!code-sql[DP EntityServices Concepts#TREAT_ISOF]~/samples/snippets/tsql/VS_Snippets_Data/dp entityservices concepts/tsql/entitysql.sql#treat_isof)]

请参阅