IS [NOT] OF (Entity SQL)

判斷運算式的型別是否不屬於所指定的型別或它的其中一個字型別。

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

Arguments

  • expression
    任何用來判斷屬於何種型別的有效查詢運算式。
  • NOT
    否定 IS OF 的 EDM.Boolean 結果。
  • ONLY
    指定 IS OF 只在 expressiontype 型別而非它的任何子型別時傳回 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)

擲回

範例

下列 Entity SQL 查詢使用 IS OF 運算子來判斷查詢運算式的型別,然後使用 TREAT 運算子將 Course 型別的物件轉換成 OnsiteCourse 型別的物件集合。 此查詢是以 School 模型為基礎。

SELECT VALUE TREAT (course as SchoolModel.OnsiteCourse) 
   FROM SchoolEntities.Courses as course
   WHERE course IS OF( SchoolModel.OnsiteCourse)

另請參閱

概念

Entity SQL 參考