有没有办法强制LINQ to SQL执行不区分大小写的包含?
我在Entity Framework Core上使用PostgreSQL。
提前致谢!
答案 0 :(得分: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)