LINQ, language-integrated queries (Language Integrated query) is a set of extensions for the C # and Visual Basic languages. It allows writing C # or Visual Basic code to manipulate memory data in the same way as querying a database. similar to SQL.
Technically, LINQ defines about 40 query operators, such as Select, from, in, where, and order by (C #). Use these operators to write query statements. However, these queries can also be based on many types of data, and each data type requires a separate LINQ type.
Over the last 20 years, the application of object-oriented programming (object-oriented) programming technologies in industry has entered a stable stage of development. Programmers now agree with language features like classes (classes), Objects (objects), methods (methods). Looking at current and next-generation technologies, a major challenge for a new programming technology has begun to emerge, when object-oriented technology was born without addressing the complexity of reducing access and consolidating information data (accessing and integrating information). Of these, two of the most important data sources are related to the database and XML (an application under the standard Universal Markup Language). LINQ provides a more general way to add some syntax query features (general-purpose) to the. Net framework that can be applied to all sources of information (all sources of information) (query Faci Lities), which is a better way to add some relational data (relational) attributes or similar XML attributes (xml-specific) to the development language and runtime (runtime). These syntax attributes are called. NET Language Integrated Query (LINQ). It contains DLinq and XLinq.
LINQ to SQL is a database application of LINQ technology. Database technology from OLEDB,ODBC to ADO, from the ADO to the present LINQ to SQL, makes it easier for programmers to manipulate databases. The purpose of LINQ is to make queries everywhere, which of course involves querying the database. LINQ can not only query the database, but also cuid (create,update,insert,delete) can be implemented, and very convenient.
A LINQ in the additions and deletions to search:
The following is an introduction to the query and additions and deletions:
1 Create
To query the data of a table in a database, it is necessary to establish a mapping of the database tables, as if you want to use ADO to save the data in the database to the dataset, the code is as follows:
The above is a mapping of the data table. Once you have established a map of the table, you can manipulate it accordingly.
2 queries
Here is the query code: (Query with Select)
The above is the query of the database, we can write a very complex query, in fact, Inside, LINQ will write your LINQ statements, translated into SQL statements sent to the database to execute. It then returns the corresponding result. If you want to see the converted SQL statement, you can add the following sentence after the connection is established: DB. Log=console.out. This will automatically output SQL statements and query results.
3 changes
The following are examples of changes:
Add () is added to the code above.
4 Delete
Delete with remove ():
Two LINQ and XML
About XML,W3C a set of DOM models, the C # language has a library of classes that manipulate XML under the DOM model. But after the advent of LINQ, Microsoft re-made a set of XML models, and the operation of the DOM model is no different, but more simple.
The following code is an example of manipulating XML with a LINQ model:
You can see the simplicity of the LINQ model. We can also see the importance of XElement from the LINQ model. You can use XElement not only to create an XML file from scratch, but also to load from a file using the Load method. You can also remove the required elements from the database, which will use LINQ to SQL, and you can also take the elements out of the array. You can save using the Save method when the operation is complete.
The following is a brief introduction to the XML additions and deletions:
1 inserting
2 queries
We see that there is no need to force the type conversions for each element when outputting XML elements, which the C # compiler has done, and it will invoke the ToString () method of each element at the time of the output.
3 modifications
of course, you can also use the Setelement method, which is where it comes in.
4 Delete
Deleting an element also allows the Setelement method to be applied, and setting an element to null would delete the element.
From the simple introduction above, we can clearly see how simple it is to manipulate XML using LINQ, which is also a big advantage.
Common functions in three LINQ
LINQ provides a number of function operations, the following is a list of some commonly used functions:
First explain the meaning of lazy in the second column. We know that there is a term called: Lazy evalution. This means that the program does not evaluate it when it is not in use.
Because LINQ provides these operations so that it is very powerful, specific use can be specific to check, in the actual programming to use the experience. This is the first introduction to LINQ, and the next blog will show you how to develop a WPF program in C #.
C # Getting Started sharing (eight)--linq