LINQ | Filtering Operator | where
Filtering operators are those operators which are used to filter the data according to the user requirement from the given data source or from the given sequence. For example, in an employee record, we want to get the data of the employees whose age in 21. So, we filter the record, according to their age. In LINQ, you can filter using the following operators:
Where operator filters the value according to the predicate function. Or in words, we can say it returns the values from the sequence based on the given condition or criteria. Where clause is not a mandatory clause in the query.
Where Clause in Query Syntax: The where clause is used to filter the query according to the given condition. You can provide a condition to where clause using lambda expression or by using Func delegate type. Where clause supports query syntax in both C# and VB.Net languages. Query Syntax of Where clause is as shown in the below example.
Employee Name: Anjita Employee Name: Soniya Employee Name: Rohit
Where Clause in Method Syntax: In Method syntax, Where clause works as a method. It present in both the Queryable and Enumerable class. It supports method syntax in both C# and VB.NET languages. The use of the Where method is shown in the below example.
Employee Name: Supriya Employee Name: Anil Employee Name: Anju
Multiple Where Clause: In LINQ, you are allowed to use multiple where clause or Where method in the single query. As shown in the below example: