0

I've been struggling with this for a couple of hours and would appreciate some help/advice if possible.

I have a list of ID's - List() I have a list of products - List()

I want to pull all rows from the product list where an ID exists.

Thanks in advance.

dotnetnoob
  • 10,783
  • 20
  • 57
  • 103

3 Answers3

1

You could use contains

var items = products.Where(p => idList.Contains(p.ID));
AlexanderBrevig
  • 1,967
  • 12
  • 17
  • Seems I was very close - I'm sure I had this identical syntax at one stage - but obviously not! Thanks this works. – dotnetnoob Nov 03 '14 at 14:27
1

You need something like this?

List<Product> products = // initialize list
List<int>     IDs =      // initialize list

List<Product> containedProducts = products.Where(p => IDs.Contains(p.ID)).ToList();
İsmet Alkan
  • 5,361
  • 3
  • 41
  • 64
0
var result = from p in products
             join i in ids
             on p.Id = i
             select p;
neo
  • 1,952
  • 2
  • 19
  • 39