From the course: .NET Essentials: LINQ for Databases

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use the Contains method for

Use the Contains method for - .NET Tutorial

From the course: .NET Essentials: LINQ for Databases

Start my 1-month free trial

Use the Contains method for

- [Instructor] Here's a scenario, when I want to use the results from one query as the criteria for a where clause in another query. So what I have here is my first query is from p in products where the unit price is greater than 90. And then I want to select out the product ID. So if it run just this query, I get three items in my results. These are the three product IDs that I want to use in my where clause. Now let's take a look at the orders details. That's what I'm going to query next, the order details. So if I look at what's available there, so I see that the order details has the order ID, product ID, unit price, quantity, and discount, and some navigation links. So I want to be able to query on this column, the product ID. So here's the solution I'm going to write my query, and then I can use the list class has a contains method that determines whether an item's contained in the list. So what I do here is…

Contents