Forcing Case Insensitive String.Contains in Entity Framework Core

.net c# case-insensitive entity-framework-core string

Question

Is there any way to force LINQ to SQL to perform a case-insensitive Contains?

I'm working with PostgreSQL on Entity Framework Core.

1
5
10/8/2019 10:19:37 AM

Popular Answer

Case insensitive name of tables and properties in Entity Framework 7

With reference to the answer above, no. There is no way to further load case sensitivity checks at an even lower level. You'll have to perform exactly what this person did:

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

Here's an example on the latest LINQ syntax.

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));

Focus on the SingleOrDefault() segment:

cp.CurrencySource.Abbreviation.Equals(exchangeAbbrv, StringComparison.InvariantCultureIgnoreCase)
0
2/27/2019 10:16:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow