使用Linq返回与参数列表中的所有匹配的所有记录

时间:2012-12-20 18:23:45

标签: linq entity-framework

我有一个简单的表,其中包含CustomerID&产品代码。使用以下Linq查询,我获得了购买10EDUC 12CONV并且未购买10CONV和11CONV的所有ID的列表。我需要做的是让它返回购买10EDUC 12CONV并且没有购买10CONV和11CONV的ID。

有什么想法? TIA

var IncludePredicate = PredicateBuilder.True<Products>(); 
var ExcludePredicate = PredicateBuilder.True<Products>(); 
List<string> IncludeProducts = new List<string>();
List<string> ExcludeProducts = new List<string>();
ExcludeProducts.Add("10CONV");
ExcludeProducts.Add("11CONV");


IncludeProducts.Add("10EDUC");
IncludeProducts.Add("12CONV");
IncludePredicate = IncludePredicate.And(m=>IncludeProducts.Contains(m.Service));
ExcludePredicate = ExcludePredicate.And(m => ExcludeProducts.Contains(m.Service));
var IncludeResults = (from d in Products
                          .AsExpandable()
                          .Where(IncludePredicate)
                          .Distinct()
                              select d.CustomerID
                              )
                              .Except(from ex in Services
                                          .Where(ExcludePredicate)
                                          select ex.CustomerID);

0 个答案:

没有答案