2009-08-26 35 views
3

如果我運行這個在C#爲什麼sql查詢在c#和vb.net上運行時在linq查詢上有所不同?

from p in Addresses where p.Address2 == null select p.AddressID 

,如果我運行此下vb.net

from p in Addresses where p.Address2 = nothing select p.AddressID 

它產生這個查詢生成此查詢

SELECT [t0].[AddressID] 
FROM [dbo].[Address] AS [t0] 
WHERE [t0].[Address2] IS NULL 

SELECT [t0].[AddressID] 
FROM [dbo].[Address] AS [t0] 
WHERE [t0].[Address2] = '' 

p.Address2是一個接受空值的varchar字段

爲什麼vb.net是「錯誤的」?

+1

未經測試,但是它應該不是來自p地址,其中p.Address2是無選擇p.AddressID' –

回答

9

在VB中,空檢查是用「is」關鍵字來控制的。

試試這個;

from p in Addresses where p.Address2 is nothing select p.AddressID