Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of Linq To Sql performance with examples

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Linq To Sql performance example analysis", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Linq To Sql performance example analysis" bar!

Linq To Sql performance

Linq To Sql performance has been mentioned by many people. Linq To Object performance has been discussed more. It is true that its own lookup is slower. But when the amount of data is particularly large, more time is spent on allocating virtual memory, then the difference between them is not so obvious. How does Linq To Sql improve performance?

*, using delayed loading (deferred loading) technology. Statement is declared, but not executed immediately, but only when it is really needed.

Second, the cache technology is adopted. When the data that has been fetched from memory is extracted in turn, it will be returned from the cache first, rather than accessing the database again. Of course, the author suggests that it is not necessary to use Linq To Sql when not using objects. For example, when just populating DataView or DataGrid, returning dataset or datatable is much faster than using Linq To Sql.

Look at the following example:

Var products = db.ExecuteQuery ("SELECT [Product List] .ProductID, [Product List] .ProductName" + "FROM Products AS [Product List]" + "WHERE [Product List] .Discontinued = 0" + "ORDER BY [Product List] .ProductName;") .ToList ()

What it returns is the collection of product. Not dataset or datatable or anything like that. Here, you can boldly use this function to continue splicing your sql. Take a look at the following

Db.ExecuteCommand ("UPDATE Products SET UnitPrice = UnitPrice + 1.00")

When it is doing batch processing, you can't do without it. Of course, if you don't think performance is a problem, use the submitchange method to update it. To put it simply, when Linq To Sql batch updates, SubmitChange will only update one by one. Waste of time and resources. This interface just satisfies the problem of batch update or deletion.

Thank you for your reading, the above is the content of "Linq To Sql performance example Analysis", after the study of this article, I believe you have a deeper understanding of the Linq To Sql performance example analysis of this problem, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report