O'Reilly logo

Code-First Development with Entity Framework by Sergey Barskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filtering data in queries

Filtering refers to the process of narrowing down the results of your query base on a condition. Let's take a look at both syntaxes of LINQ using filtering as an example:

var query = from person in context.People
            where person.HeightInFeet >= 6
            select person;
var methodQuery = context.People.Where(p => p.HeightInFeet >= 6);

The purpose behind the query is to retrieve the people who are at least 6 feet tall. This means that we have a specific condition that all the data in our results must match. Both lines of code answer this question. The first line uses query syntax. There are distinct parallels to the SQL query syntax. We have the from, where, and select blocks of code. Their order is different from SQL, but they certainly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required