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 LINQ retrieves data

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

Share

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

This article is about how LINQ retrieves data. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

LINQ has a lot to learn. Here we mainly introduce LINQ data retrieval, including LINQ retrieval of data in the database where Customers table City equals London and so on.

LINQ retrieves data

The syntax structure provided by LINQ retrieval data is similar to that of SQL, which makes it easier for us to use. Northwind.dbml automatically wraps a context object NorthwindDataContext class, which includes all the entity classes and stored procedure mapping methods that we want to use in the Northwind database, and also provides a method to manipulate the table data. When we use it, we do not need to care about how it connects to the database and operates on the underlying data. In fact, this infrastructure is already included in the Northwind.dbml file! Use notepad to open Northwind.dbml, you can find that this is a pure XML structured file, which contains the database connection string and some database entity class mapping, at the same time, the Northwind.designer.cs file has also done a lot of basic work, interested readers can study their own code, may be helpful to solve practical problems. This article does not explain the specific structure of this file in detail here.

The following example shows that the data in the database where the Customers table City equals London is retrieved through LINQ and printed in the Command window.

Using (NorthwindDataContext context = new NorthwindDataContext ()) {var results = from curstomers in context.Customers where curstomers.City = = "London" orderby curstomers.CompanyName select curstomers; foreach (var curstomers in results) {Console.WriteLine ("Company is {0} and Contact is {1}", curstomers.CompanyName, curstomers.ContactName);} / / Pause to see the output Console.ReadLine ();} Thank you for reading! This is the end of the article on "how to retrieve data in LINQ". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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