How can I use wildcards in EF Core Like function

.net-core c# entity-framework entity-framework-core

Question

.NET Core 2.2.0

I would like to use Wildcards in EF Core's Like function, but it doesn't work the way I expect and I've read about in some posts (best example here)

My Code:

List<string> list = new List<string>();
list.Add("Hi fransois");
list.Add("Hi francois");
list.Add("Hi françois");

List<string> testa = list.Where(a => EF.Functions.Like(a, "%francois%")).ToList();      // Results in 1 hit, as expected
List<string> testb = list.Where(b => EF.Functions.Like(b, "%françois%")).ToList();      // Results in 1 hit, as expected
List<string> testc = list.Where(c => EF.Functions.Like(c, "%fran[cç]ois%")).ToList();   // Results in 0 hits, EXPECTED: 2

Why doen't this work as expected?

1
2
4/15/2019 2:08:36 PM

Popular Answer

Unfortunately it looks like this isn't gonna work. But there is a workaround using Regex:

    Regex regex = new Regex("fran[cç]ois");
    List<string> testd = list.Where(d => regex.IsMatch(d)).ToList();

This works.

0
4/17/2019 6:08:05 AM


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