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.

Enumerable and Queryable extension methods

Enumerable and Queryable extension methods - .NET Tutorial

From the course: .NET Essentials: LINQ for Databases

Start my 1-month free trial

Enumerable and Queryable extension methods

- [Instructor] The query operators are implemented as extension methods. Let's see where they live in the .NET library. The first thing I want to look at in the sample code is the data sources. So I have two different data sources. At the top I'm declaring a variable, colors, and it's of type list of string that contains some color names. And the other data source is from Entity Framework. It's this Products DB set. My goal is to filter these data sources and I'm going to use the where extension method to do that. So on line five and line eight I'm using that where extension method. Now where extension method expects a predicate function, so that's what I'm passing in here. So, I want to filter all the color strings to start with an uppercase B, and for the second data source, I want to query all the product names that start with F. You notice how the syntax is nearly identical? The only difference is I had to work…

Contents