为什么在c#和vb.net上运行时,linq查询的sql查询是不同的?

Fre*_*dou 3 c# linq vb.net

如果我在c#下运行

from p in Addresses where p.Address2 == null select p.AddressID
Run Code Online (Sandbox Code Playgroud)

它会生成此查询

SELECT [t0].[AddressID]
FROM [dbo].[Address] AS [t0]
WHERE [t0].[Address2] IS NULL
Run Code Online (Sandbox Code Playgroud)

如果我在vb.net下运行它

from p in Addresses where p.Address2 = nothing select p.AddressID
Run Code Online (Sandbox Code Playgroud)

它会生成此查询

SELECT [t0].[AddressID]
FROM [dbo].[Address] AS [t0]
WHERE [t0].[Address2] = ''
Run Code Online (Sandbox Code Playgroud)

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

为什么vb.net是"错误的"?

Ali*_*söz 9

在VB中,使用"is"关键字控制空检查.

试试这个;

from p in Addresses where p.Address2 is nothing select p.AddressID
Run Code Online (Sandbox Code Playgroud)