强制不区分大小写的String.Contains in Entity Framework Core

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

有没有办法强制LINQ to SQL执行不区分大小写的包含?

我在Entity Framework Core上使用PostgreSQL。

提前致谢!

c# .net string entity-framework-core case-insensitive
1个回答
0
投票

Case insensitive name of tables and properties in Entity Framework 7

参考上面的答案,没有。无法在更低级别进一步加载区分大小写检查。你必须完全履行这个人的所作所为:

How do I make contains case-insensitive in ef core 2?

这是最新LINQ语法的示例。

var tickerObj = _unitOfWork.GetRepository<CurrencyPair>()
                .GetQueryable()
                // .Where() and .Include() omitted for brevity
                .SingleOrDefault(cp => string.Concat(
                    cp.PartialCurrencyPairs.FirstOrDefault(pcp => pcp.IsMain).Currency.Abbrv,
                    cp.PartialCurrencyPairs.FirstOrDefault(pcp => !pcp.IsMain).Currency.Abbrv)
                    .Equals(ticker, StringComparison.InvariantCultureIgnoreCase)
                && cp.CurrencySource.Abbreviation.Equals(exchangeAbbrv, StringComparison.InvariantCultureIgnoreCase));

专注于SingleOrDefault()细分:

cp.CurrencySource.Abbreviation.Equals(exchangeAbbrv, StringComparison.InvariantCultureIgnoreCase)
© www.soinside.com 2019 - 2024. All rights reserved.