首页 新闻 会员 周边

请问linq to entities中怎么判断一个集合是否包含另一个集合啊

0
悬赏园豆:30 [已解决问题] 解决于 2012-02-16 16:33

请问linq to entity中怎么判断一个集合是否包含另一个集合啊?

示例数据(来自:请教List求交集的Linq问题):

class Program
{
static void Main(string[] args)
{
List<A> aList = new List<A>()
{
new A(){ Id=1,Names=new List<string>(){"a","b","c"}},
new A(){ Id=2,Names=new List<string>(){"b","c","d"}},
new A(){ Id=3,Names=new List<string>(){"c","d","e"}},
new A(){ Id=4,Names=new List<string>(){"e","d","f"}},
new A(){ Id=5,Names=new List<string>(){"e","f","g"}}
};
List<string> test = new List<string>() { "e", "f" };

var val=//求aList中Names属性包含test的A的集合

Console.Read();
}
}

public class A
{
public int Id { get; set; }

public List<string> Names { get; set; }
}

也就是得到ID为4和4的A的集合

artwl的主页 artwl | 专家六级 | 园豆:16736
提问于:2012-02-16 15:49
< >
分享
最佳答案
0
var val=aList.Where(a => test.All(t => a.Names.Contains(t))).ToList();
收获园豆:30
LCM | 大侠五级 |园豆:6876 | 2012-02-16 16:05

LINQ TO Entities没用过,目测a.Names.Contains是有问题的。。。

水牛刀刀 | 园豆:6350 (大侠五级) | 2012-02-16 16:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册