共用方式為


ISNULL (Entity SQL)

判斷查詢表達式是否為 Null。

語法

expression IS [ NOT ] NULL

論點

expression 任何有效的查詢表達式。 不能是集合、具有集合成員或具有集合類型屬性的記錄類型。

NOT 否定EDM。IS NULL 的布爾值結果。

傳回值

true 如果 expression 傳回 null,則為 ,否則為 false

備註

用來 IS NULL 判斷外部聯結的 元素是否為 Null:

select c
      from LOB.Customers as c left outer join LOB.Orders as o
                              on c.ID = o.CustomerID
      where o is not null and o.OrderQuantity = @x

用來 IS NULL 判斷成員是否有實際值:

select c from LOB.Customer as c where c.DOB is not null

下表顯示在某些模式上的行為 IS NULL 。 在叫用提供者之前,所有例外狀況都會從客戶端擲回:

樣式 行為
null IS NULL 傳回 true
TREAT (Null AS EntityType) 為 NULL 傳回 true
TREAT (Null AS ComplexType) 為 NULL 擲回錯誤。
TREAT (Null AS RowType) 為 NULL 擲回錯誤。
EntityType IS NULL 傳回 truefalse
ComplexType IS NULL 擲回錯誤。
RowType IS NULL 擲回錯誤。

範例

下列 Entity SQL 查詢會使用IS NOT NULL 運算符來判斷查詢表達式是否不是 Null。 查詢是以 AdventureWorks 銷售模型為基礎。 若要編譯並執行此查詢,請遵循下列步驟:

  1. 遵循 如何:執行會傳回 StructuralType 結果的查詢中的程式。

  2. 將下列查詢當做自變數傳遞至 ExecuteStructuralTypeQuery 方法:

SELECT VALUE product FROM AdventureWorksEntities.Products 
    AS product WHERE product.Color IS NOT NULL

另請參閱