SQL word wide "%like%" search in Entity Framework 6 using lambda expression

c# entity-framework entity-framework-6 linq

Accepted Answer

Your issue's root is as follows:

result = result.Where(t => searchTextArray.Any(s => t.title.ToLower().Contains(s)));

Any() if a one match is discovered, it returns true (or more, but it stops checking after one). Using is comparable to using in SQL.OR .

What you want is this:

result = result.Where(t => searchTextArray.All(s => t.title.ToLower().Contains(s)));

All() if all elements (in ) return true, thensearchTextArray ) own a match (in this instance, if allsearchTextArray components are present in a specifiedtitle (Using this is comparable to using in SQL).AND .

2
7/16/2018 7:59:03 PM

Popular Answer

Change in response to the new failure mode (too many results). All to Any:

    result = result.Where(t => searchTextArray.All(s => t.title.ToLower().Contains(s)));


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