Toubi Toubi - 1 year ago 62
C# Question

implementing "where in" clause in Lambda?

I have a expression which is returning me Ids:

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

Another structure has Notifications and requirement is to filter notifications for which Id is provided in

var AllNotifications = _notificationRepos.All(n => n.ExpiresAt > DateTime.UtcNow).ToList();

I m trying the following code to query all Notifications but not getting how to impement "where in" in my expression.

Please help

Answer Source

If it is selecting based off of 1 id

selectAll.where(x => == varId)

If you pass in multiple ids then you need to use .Contains().

selectAll.where(x => idList.contains(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download