What Is a Language Integrated Query?
Language integrated query is a new technology provided by Microsoft Corporation. It can directly introduce query capabilities into programming languages (such as C #, Visual Basic, etc.) supported by the .NET Framework 3.5, enabling developers to form collection-based queries in application code without having to use a separate query language. Query operations can be conveyed through the programming language itself, rather than embedded in the application code as strings. [1]
- With the exception of the simplest applications, almost all applications need to process data. Historically, most applications provided their own logic to perform these operations. However, this design will cause the code in the application to be tightly "coupled" with the data it is processing; once the data structure changes, you may need to modify the code significantly to accommodate the change. The designers of the Microsoft .NET Framework share the pain of programmers. After a long period of careful consideration, they finally provided a feature that "abstracted" the mechanism for querying data from application code. This feature is called "Language Integration Query".
- The designers of LINQ borrowed a lot
- LINQ technology mainly includes 4 independent technologies: LINQ tO Objects, LINQ to SQL, LINQ to DataSet and LINQ to XML. They query and process object data (such as collections), relational data (such as SQL Server databases, etc.), DataSet object data, and XML structures (such as
- The key to using LINQ is mainly two points: one is the query expression and the other is the object-relational designer (O / R designer), which is somewhat similar to the dataset designer. After mastering these two key technologies, other LINQ technologies can be easily solved.
- All LINQ query operations consist of the following three parts:
- 1) Get the data source.
- 2) Create a query, define a query expression, and save the query expression in a query variable.
- 3) Use the query variable to execute the query.
- There are three main ways to display query results:
- 1) Call the property or method of the query variable to obtain further results.
- 2) In the foreach statement, all query results are obtained by iterating through the query variables.
- 3) Use data binding to display the query results, that is, bind the BindingSource to the query variable, then bind the control to the BindingSource, and then display the results on the form. [4]
- LINQ defines a set of common standard query operators that can be used in the .NET Framework 3.5 and above. Use these standard query operators to project, filter, and traverse the data in the above data sets in memory. Several advantages of LINQ are explained below.
- First, integration
- Integrate the query syntax into the C # language and become a syntax of C #; integrate and encapsulate the work before the complex query before, let the developer focus on the query.
- Second, unity
- Using a unified query syntax for supported data sources makes code maintenance easier.
- Third, scalability
- LINQ provides the LINQ provider model, which can create or provide providers for LINQ to support more data sources, such as LINQ to JavaScript and LINQ to MySQL.
- Fourth, descriptive programming
- Developers only need to tell the program what to do, and the program judges how to do it, which improves the development speed.
- V. Abstraction
- Use an object-oriented approach to abstract data. LINQ uses a so-called OR Mapping method to transform relational data into objects and object-based description data.
- Composition
- LINQ can split a complex query into multiple simple queries. The results returned by LINQ are based on the IEnumerable <T> interface, so you can continue to query the query results.
- Seven, convertibility
- LINQ can convert the content of one data source to other data sources, which is convenient for users to do data migration. [3]