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

How to understand the LINQ TO SQL loading mode

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

Share

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

This article introduces the relevant knowledge of "how to understand the LINQ TO SQL loading mode". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In LINQ TO SQL, there are two main LINQ TO SQL loading modes: direct loading and delayed loading. There is an option to control this; DeferredLoadingEnabled. This is an attribute of DataContext, which defaults to true. So, what is delayed loading? To put it simply, load on demand, that is, load only when needed. Of course, this has some advantages.

The key point, however, is that if we are sure that some part of the data is to be loaded, then it may not be appropriate to delay loading again, and direct loading should be chosen at this time.

Let's look at such an example.

Static void Main (string [] args) {NorthwindDataContext db = new NorthwindDataContext (); var custQuery = from cust in db.Customers where cust.City = = "London" select cust; foreach (Customer custObj in custQuery) {Console.WriteLine ("CustomerID: {0}", custObj.CustomerID); foreach (Order ord in custObj.Orders) {Console.WriteLine ("\ tOrder ID: {0}", ord.OrderID) Foreach (OrderDetail detail in ord.OrderDetails) {Console.WriteLine ("\ t\ tProduct ID: {0}", detail.ProductID);} Console.Read ();}

The above is to query a customer list, but when reading, we should not only read the customer list, but also read its related orders and details.

It is important to note that we have not set the load mode of db, so we will use the deferred LINQ TO SQL load mode.

This is the end of the content of "how to understand the LINQ TO SQL loading mode". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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