DevArt Oracle EF Core-不区分大小写的字符串比较+ NULLS

问题描述 投票:0回答:1

[当涉及NULL时,当将DevArt EF Core与Oracle一起使用时,我似乎找不到任何明智/可靠的方式来执行不区分大小写的字符串比较

假设存在一个带有“名称”列的表,该表是可为空的字符串(varchar(50))。

首先,这些选项根本不影响生成的SQL;

OracleEntityProviderConfig.Instance.QueryOptions.CaseInsensitiveComparison = true;
OracleEntityProviderConfig.Instance.QueryOptions.CaseInsensitiveLike = true;
OracleEntityProviderConfig.Instance.QueryOptions.UseCSharpNullComparisonBehavior = true;

。ToLower();

var result = repo.FirstOrDefault(x => x.Name.ToLower() == searchValue.ToLower());

这是可行的,但是如果searchValue为null,则x.Name.ToLower()会导致NREx,因此不能可靠地使用它(不进行大量丑陋的null检查,并且不能在LINQ语句中使用?。)

。Equals()

result = repo.FirstOrDefault(x => x.Name.Equals(searchValue, StringComparison.CurrentCultureIgnoreCase));

此生成;

WHERE UPPER("Name") = UPPER('somevalue')

但是如果searchValue为null,则它永远不会匹配,因为比较null的唯一有效方法是

WHERE "Name" is null

我认为应该将EF Core DevArt适配器不将Name ='value'更改为is null

oracle entity-framework entity-framework-core devart
1个回答
0
投票

最后编写了ToLowerNullSafe()字符串扩展方法,该方法(LINUX可以防止空值)被LINQ接受并正确地转换为'is null'

© www.soinside.com 2019 - 2024. All rights reserved.