EF.Functions.Contains including multiple keywords

一个人想着一个人 提交于 2019-12-11 10:03:01

问题


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:


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


来源:https://stackoverflow.com/questions/55230001/ef-functions-contains-including-multiple-keywords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!