使用linq,如何检索其属性列表与另一个列表匹配的项目列表?
拿这个简单的例子和伪代码:
List<Genres> listofGenres = new List<Genre>() { "action", "comedy" });
var movies = _db.Movies.Where(p => p.Genres.Any() in listofGenres);
Run Code Online (Sandbox Code Playgroud) 我设置了一个搜索文本框,其中搜索将单独抓取每个单词并使用“包含”搜索字段。
有没有办法通过 Contains 搜索字符串数组?
//Keep in mind that the array would be generated dynamically through textbox
string[] searchWords = { "hello", "world", "today" };
var articles = _swmDbContext.Articles
.Include(c => c.Category)
.Where(a => a.Title.Contains(searchWords));
Run Code Online (Sandbox Code Playgroud)
searchWords 显然不起作用,但试图展示我想要实现的目标。searchWords[0] 之所以有效,是因为它只是一个单词。
我还按照其他链接中的建议尝试了下面的操作,但现在当我运行调试器或探查器时,WHERE 子句不会显示在查询中:
`var articles = _swmDbContext.Articles
.Include(c => c.Category)
.Where(a => searchWords.Any(w => a.Title.Contains(w)));
Run Code Online (Sandbox Code Playgroud)
`