Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - Select distinct in

I have a table called Tag with a column called Label and a column called AuctionId. I also have an array of strings which are search terms. I want to write some Linq to Entities code which will give me a distinct list of AuctionIds where the the Label matches one of the search terms. Here is the pseudocode for this:

return a list of unique AuctionIds where Label is in searchTerms

How can this be done?

like image 570
Sachin Kainth Avatar asked Feb 17 '12 11:02

Sachin Kainth


1 Answers

You can use Contains() on the list.

List<String> AuctionIDs = (from tagItem in Tags
                           where searchItems.Contains(tagItem.Label)
                           select tagItem.AutionID).Distinct().ToList();
like image 100
Kenneth Henderick Avatar answered Sep 27 '22 18:09

Kenneth Henderick