LINQ哪里列表中包含的任何名单中 [英] linq where list contains any in list

查看:144
本文介绍了LINQ哪里列表中包含的任何名单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LINQ,我怎么可以检索项目的列表,它的属性列表匹配另一个列表?

拿这个简单的例子,伪code:

 列表<流派与GT; listofGenres =新的List<&体裁GT;(){行动,喜剧});
变种电影= _db.Movies.Where(p值=>在listofGenres p.Genres.Any());


解决方案

听起来像你想要的:

  VAR电影= _db.Movies.Where(P => p.Genres.Intersect(listOfGenres)。任何());

Using linq, how can I retrieve a list of items where it's list of attributes match another list?

Take this simple example and pseudo code:

List<Genres> listofGenres = new List<Genre>() { "action", "comedy" });   
var movies = _db.Movies.Where(p => p.Genres.Any() in listofGenres);

解决方案

Sounds like you want:

var movies = _db.Movies.Where(p => p.Genres.Intersect(listOfGenres).Any());

这篇关于LINQ哪里列表中包含的任何名单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆