C# 为什么Linq对postgresql使用tolower出现;是空的;
以下Linq代码: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
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*