-3

i am very new in LINQ so,I can't understand what the exact Linq query is of this SQLquery.

Please give exact Linq Query similar to this SQL query.

Select  * From tblProduct 
Where ProductId In 
      (Select  ProductId  from  tblViewer Where ViewerId = 123)
Sk Asraf
  • 163
  • 2
  • 14

1 Answers1

4

Contains is the most straightforwrad way to implement an IN statement, so it would be something like:

tblProduct.Where(p => tblViewer.Where(v => v.ViewerId == 123)
                               .Select(v => v.ProductId)
                               .Contains(p.ProductId)
                );
D Stanley
  • 149,601
  • 11
  • 178
  • 240