1

我使用实体框架 4 和 linq/lamda 表达式。我确定它很简单,但我试图用数组查询集合但获取包含所有数组值的记录。

基本上我在做什么

var records = collection.where(x.classifications.Any(y=> Array.Contains(y.ClassificationID))).ToList()

这在某种意义上有效,它返回包含任何数组值的记录,但我如何只获取包含数组中所有值的记录。

希望这是有道理的

编辑:

我将下面的评论标记为答案,因为我必须在查询中使用 ALL 才能使其正常工作,但是我还必须稍微重新编写我的查询。这就是我最终拥有的...

  var records = collection.Where(x=> Array.All(c=> x.Classifications.Select(l=>l.ClassificationID).Contains(c)))
4

1 回答 1

0

What about using All instead of Any?

var records = collection.Where(x => x.classifications.All(y => Array.Contains(y.ClassificationID)))
                        .ToList()
于 2013-02-21T13:07:48.103 回答