请问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的集合
var val=aList.Where(a => test.All(t => a.Names.Contains(t))).ToList();
LINQ TO Entities没用过,目测a.Names.Contains是有问题的。。。