Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Linq对postgresql使用tolower出现;是空的;_C#_Linq_Postgresql_Linq To Sql - Fatal编程技术网

C# 为什么Linq对postgresql使用tolower出现;是空的;

C# 为什么Linq对postgresql使用tolower出现;是空的;,c#,linq,postgresql,linq-to-sql,C#,Linq,Postgresql,Linq To Sql,以下Linq代码: db.Where(t => t.ToLower().Equals(name.ToLower())) 生成以下postgresql查询: SELECT "Extent1"."Name" FROM "Custom" AS "Extent1" WHERE lower("Extent1"."Name") = lower(@__linq__0) OR lower("Extent1"."Name") IS NULL AND lower(@__linq__0) IS

以下Linq代码:

db.Where(t => t.ToLower().Equals(name.ToLower()))
生成以下postgresql查询:

SELECT "Extent1"."Name"
FROM "Custom" AS "Extent1"
WHERE lower("Extent1"."Name") = lower(@__linq__0) OR 
      lower("Extent1"."Name") IS NULL AND  lower(@__linq__0) IS NULL

为什么查询包含“IS NULL”条件

可能是因为名称字符串变量可以为null,表的值也是如此。
不确定postgress中的null==null可能是因为您的name字符串变量可以为null,表的值也可以为null。
不确定如果postgress中的null==null

在SQL中无法使用
=
null
进行比较,则需要使用
IS
关键字

由于要返回
名称
列等于(小写后)传递的字符串的所有行,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

注意:
优先于
在SQL中,您无法使用
=
空值进行比较,您需要使用
IS
关键字

由于要返回
名称
列等于(小写后)传递的字符串的所有行,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
注意:
在C中优先于
,您不能这样做

null == null  --> null instead of true / false
因为你的字段理论上可以是空的

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
在C#中,你做不到

null == null  --> null instead of true / false
因为你的字段理论上可以是空的

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

如何修改它可能不会出现“是空的”我不知道你是否可以,字符串的定义允许空。但是不要太担心,如果你没有空值,那么性能成本最低。非常感谢。你可能还会问一个问题?可以选择“Extent1”。“Name”=>选择*如何修改它可能不会出现“IS null”我不知道你是否可以,字符串定义允许空值。但是不要太担心,如果您没有空值,那么性能成本会非常低。非常感谢您。您可能还会问一个问题?可以选择“Extent1”。“Name”=>SELECT*