EF.Functions.Contains including multiple keywords

asp.net-core entity-framework-core linq

Question

I need to search on multiple columns (LearningModuleDesc and LearningModuleContent which works using the || statements below) but I also need to search on multiple keywords. .Net Core 2.2 and EF Core does not support the string array with Contains (like the example below) but some guidance of how I would go about this would be great.

string[] stringarray = new string[] { "mill", "smith" };

var results =  _context.LearningModules
.Where(x => EF.Functions.Contains(x.LearningModuleDesc, stringarray)
|| EF.Functions.Contains(x.LearningModuleContent, stringarray)
);
1
1
3/18/2019 9:02:28 PM

Accepted Answer

If I understand correctly, you are looking for something like this

 var results = _context.LearningModules.Where(
   x => stringarray.Any(t => x.LearningModuleDesc.Contains(t)) || 
        stringarray.Any(t => x.LearningModuleContent.Contains(t)))
0
3/18/2019 9:21:13 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