Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Linq从参数列表中返回与all匹配的所有记录_Linq_Entity Framework - Fatal编程技术网

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

使用Linq从参数列表中返回与all匹配的所有记录,linq,entity-framework,Linq,Entity Framework,我有一个带有CustomerID和ProductCode的简单表。使用下面的Linq查询,我得到了购买10EDUC或12CONV而没有购买10CONV和11CONV的所有ID的列表。我需要做的是让它返回那些购买10EDUC和12CONV而没有购买10CONV和11CONV的人的ID 有什么想法吗?短暂性脑缺血发作 var IncludePredicate = PredicateBuilder.True<Products>(); var ExcludePredicate = Pred

我有一个带有CustomerID和ProductCode的简单表。使用下面的Linq查询,我得到了购买10EDUC或12CONV而没有购买10CONV和11CONV的所有ID的列表。我需要做的是让它返回那些购买10EDUC和12CONV而没有购买10CONV和11CONV的人的ID

有什么想法吗?短暂性脑缺血发作

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);
var IncludePredicate=PredicateBuilder.True();
var ExcludePredicate=PredicateBuilder.True();
List IncludeProducts=新列表();
List ExcludeProducts=新列表();
不包括产品。添加(“10CONV”);
不包括产品。添加(“11CONV”);
包括产品。添加(“10EDUC”);
包括产品。添加(“12CONV”);
IncludePredicate=IncludePredicate.And(m=>IncludeProducts.Contains(m.Service));
ExcludePredicate=ExcludePredicate.And(m=>ExcludeProducts.Contains(m.Service));
var IncludeResults=(来自产品中的d
.AsExpandable()
.其中(包括指示)
.Distinct()
选择d.CustomerID
)
.不包括(从服务业交货)
.Where(不包括谓词)
选择ex.CustomerID);

英语中“and”和“and”或“or”的不精确性阻碍了这里的发展:“and't buy 10CONV and 11CONV”,你的意思是“没有买10CONV或11CONV”,还是“可能买了10CONV或11CONV,但不是10CONV和11CONV在一起”?我认为我们可以忽略排除产品来简化事情。我只需要为同时购买10EDUC和12CONV的人返回ID。可能是Risky的重复,这适用于两个列表/数组,但不适用于从数据库返回的多个记录。至少我似乎不能让它工作。