Language-Integrated Query (LINQ) is the name of a set of technologies that are built on the direct integration of query functionality into the C # language (as well as Visual basic and any other possible. NET language). with LINQ, the query is now a high-level language construct, just like classes, methods, events, and so on.
For developers writing queries, the most obvious "language integration" part of LINQ is the query expression. You use the same basic query expression pattern to query and transform data in SQL databases, ADO datasets, XML documents and streams, and. NET collections.
The following example shows the full query operation. complete operations include creating a data source, defining a query expression, and executing a query in a foreach statement.
C # Replication
class linqqueryexpressions{static void Main () {//specify the data source. int[] scores = new int[] {97, 92, 81, 60 }; //Define the query expression. Ienumerable<int> scorequery = from score in scores where score > select score; //Execute the query. foreach (int i in scoreQuery) { Console.Write (i + //output:97, Bayi
For more information about the basic LINQ knowledge in C #, see Getting Started with LINQ in C #.
Query Expressions Overview
-
-
query expressions are easy to master because they use many common C # language constructs. getting Started with LINQ in C #. " > For more information, see Getting Started with LINQ in C #.
-
type relationships in LINQ Query Operations (C #). " > For more information, see Type Relationships in LINQ Query Operations (C #).
The query is not executed until you iterate through the query variables in the foreach statement. For more information, see Introduction to LINQ Queries (C #).
At compile time, the query expression is converted to the standard query operator method call according to the rules set in the C # specification.c# Language Specification and Standard Query Operators Overview. " > For more information, see the C # Language specification and standard Query Operators overview.
-
as a rule for writing LINQ queries, it is recommended that you use the query syntax as much as possible, and only if necessary to use method syntax. query expressions are often easier to read than equivalent expressions written in method syntax.
-
count< Tsource> or max, has no equivalent query expression clause and must therefore be express Ed as a method call. " > Some query operations, such as Count <tsource> or Max, do not have an equivalent query expression clause and must therefore be represented as a method call. query Syntax and Method Syntax in LINQ (C #). " > For more information, see Query Syntax and Method Syntax in LINQ (C #).
The query expression can be compiled into an expression tree or delegate, depending on the type to which the query is applied.IEnumerable<T> query compilation to delegate. IQueryable and IQueryable<T> queries are compiled into an expression tree. For more information, see Expression trees (C # and Visual Basic).
LINQ query Expressions (C # Programming Guide)