以下Linq代码:
$select = mysqli_query($connection,"select * from temp_info where rand_number ='".$rand_number."'");
生成以下postgresql查询:
db.Where(t => t.ToLower().Equals(name.ToLower()))
为什么查询包含" IS NULL"条件?
答案 0 :(得分:0)
也许是因为你的名字字符串变量可以为null,与表的值相同。 不确定postgress中是否为null == null
答案 1 :(得分:0)
在SQL中,您无法使用NULL
与=
进行比较,您需要使用IS
关键字。
因为你想要返回NAME
列等于(小写之后)你传递的字符串的所有行,所以linq还会在生成的WHERE
比较中包含这两列的情况和字符串是NULL
。
-- column and string are != NULL and equal
lower("Extent1"."Name") = lower(@__linq__0) OR
-- column and string are both NULL
lower("Extent1"."Name") IS NULL AND lower(@__linq__0) IS NULL
注意:AND
优先于OR
。
答案 2 :(得分:0)
在C#中你无法做到
null == null --> null instead of true / false
因此,理论上你的字段可以为null
lower(name) == (lower(@__linq__0) //even if both are null
所以还包括:
lower(null) == lower(null)
等效于:
lower("Extent1"."Name") IS NULL AND lower(@__linq__0) IS NULL