Linq query using list or array of identifiers

I find it difficult to figure out how to query db using linq in C # to get all the objects matching a list or array of identifiers and put them in a list. For instance:

I have a table of elements. I want to create a method that retrieves all the elements whose identifiers are in an array or list of passes. I have googled, but it always assumes that I just want to query a list or array, not a query USING a list or array.

Thanks in advance.

+5
source share
2 answers

It looks like you want something like:

var query = items.Where(item => validIds.Contains(item.Id));

: (, , LINQ to Objects), , , , HashSet<T>.

, :

var query = from id in validIds
            join item in items on id equals item.Id
            select item;

( Stack Overflow, , , .)

+19

 var subscriptionDetails = SubscriptionMasterBL.GetSubscriptionMasterDetails();
                tempUserList = lstSubscriberUsers.Where(a => subscriptionDetails.Any(b => b.SubscriptionUserId == a.Id 
                    && b.TokenId != Guid.Empty)).ToList();
0

All Articles