In the previous article, I have already explained that all Standard Query Operators in LINQ are actually extension methods on the Ienumerable<T> and Iqueryable<T> types that are defined in the System.Linq.Enumerable and System.Linq.Queryable classes. Also, almost all LINQ query operators either accept a Func, Predicate, or Action generic delegates, and this is the reason we are able to use lambda expressions as arguments to them.
Standard Query Operators in Query Syntax
Standard Query Operators in Method Syntax
Standard Query Operators in query syntax are converted into their corresponding extension methods at compile time. So both are the same. Standard query operators can be classified based on the functionality they provide, as shown below:
You must be thinking that many SQL operators have no equivalent in LINQ, so how do we achieve those requirements? For example, we have no "IN" operator in LINQ; similarly, we have no "Top" operator in LINQ, so how do we achieve such requirements? Then be very clear that LINQ is not SQL. LINQ is designed to query in-memory collections with .NET languages, so you can apply all OOP concepts to collections to get what you want. In situations where you need an "IN" operator, you can create an array and then use the contains operator on that array. Also, LINQ is not for complex queries, and we still need to write stored procedures and all. Never consider LINQ as a replacement for SQL; these two are completely different things. At the end of the day, all LINQ queries are translated into their equivalent T-SQL underneath, because databases just understand SQL. It is the duty of the respective LINQ provider to translate LINQ queries into their datasource-specific language; for example, it is the duty of the LINQ-To-SQL LINQ provider to convert LINQ queries into necessary T-SQL.
We will learn each Standard Query Operator in the next sections.