实现Lambda中的“where in”子句?

时间:2014-01-08 23:55:56

标签: c# .net lambda

我有一个回复我的表情:

var UserNotificationIds = _notificationBidderRepos.All(u => u.BidderId == BidderId).Select(n =>n.BidderId);

另一种结构有通知,要求是过滤UserNotificationIds

中提供了Id的通知
var AllNotifications = _notificationRepos.All(n => n.ExpiresAt > DateTime.UtcNow).ToList();

我正在尝试使用以下代码来查询所有通知,但没有获得如何在我的表达式中强制“where in”。

请帮忙

3 个答案:

答案 0 :(得分:5)

如果是基于1 id

进行选择
selectAll.where(x => x.id == varId)

如果传入多个ID,则需要使用.Contains()。

selectAll.where(x => idList.contains(x.id))

答案 1 :(得分:3)

您似乎需要Contains

var AllNotifications = _notificationRepos.Where(n => n.ExpiresAt > DateTime.UtcNow 
                               && UserNotificationIds.Contains(n.Id)).ToList();

答案 2 :(得分:0)

您可以使用"包含"或者"加入"方法"其中"过滤。帖子here

中的代码示例和详细信息