Advantages and disadvantages

Source: Internet
Author: User

LINQ to SQL is a new technology developed by Microsoft to solve the data <> Object problem.

1. Advantages of LINQ to SQL

Before the release of LINQ to SQL, we only formed a string for the SQL statement, and then passed it to SQL Server through ado.net to return the result set. The drawback is that if there is a problem with SQL statement writing, it is only known at runtime, and not everyone knows about the database. However, LINQ to SQL can be used in all data-related projects. Especially when SQL Server experts are missing from the project, the powerful functions of LINQ to SQL can help us quickly complete the project. The release of LINQ to SQL frees everyone from the technical details and pays more attention to the project logic. The emergence of LINQ to SQL greatly reduces the difficulty of database application development. In essence, it builds a data access layer for programmers in advance, which is bound to accelerate the development of database applications. As a result, many programmers are freed from the use of LINQ to SQL, allowing them to focus more on business logic and coding than on databases. For beginners, LINQ to SQL allows them to quickly enter the database application development field, saving training costs.

LINQ to SQL is implemented on the basis of ado.net and C #2.0. It creates a result set and returns an object by automatically translating SQL statements. From this we can see that the SQL statements sent to SQL Server are automatically generated by LINQ to SQL. This is undoubtedly a good news for those who do not understand SQL. In particular, the LINQ to SQL statement is checked during compilation. Instead of runtime check. In this case, when a problem occurs, you can change it in time, instead of discovering the problem at runtime. Finally, LINQ to SQL is intended for object operations and is "object-oriented.

2. disadvantages of LINQ to SQL

It is much more difficult to construct a statement dynamically than to concatenate an SQL statement. It is mainly generated to solve the problem of data <> objects. All operations are targeted at objects. Therefore, we recommend that you use object query to comply with the design principles of LINQ to SQL. In fact, you can still use concatenated strings in the form of LINQ to SQL, rather than the query expression it provides. It provides two methods: DB. executequery <tentity> (string SQL) and DB. executecommand (string SQL), which receive SQL statements directly. People who are used to splicing can still call them for operations. In particular, the first response is a collection of objects, which is somewhat "oriented to the image". For the second one, when you need batch processing, you don't need it. Of course, if you think the performance is not a problem, you can use the submitchange Method for updates. Submitchange will only be updated one by one when the data is updated in a batch by using LINQ to SQL. The second method meets the needs of batch update or deletion.

3. Performance of LINQ to SQL

LINQ is indeed slower than self-implemented search. However, when the data volume is very large and the time is spent on allocating virtual memory, the difference is not that obvious. How can I improve the performance of LINQ to SQL? First, deferred loading technology is used. The statement is not executed immediately after it is declared, but is executed only when it is actually needed. Second, the cache technology is used. When the data that has been retrieved from the memory is extracted sequentially, it is returned from the cache instead of accessing the database again. Of course, when you do not need an object, you do not need to use LINQ to SQL. For example, if you only fill in dataview or DataGrid, the returned dataset or able is much faster than that implemented by using LINQ to SQL.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.