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 Linq data and objects

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

Share

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

This article mainly explains "how to understand Linq data and objects". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand Linq data and objects".

As we all know, when developing data, the data is generally relational data, but what is the relationship between data and objects? linq is mainly to solve the problem that data is not equal to objects. With Linq data and objects, there can be an one-to-one correspondence. And these are the code that can generate this kind of mapping according to the database, and it can also generate the database according to the mapping code. That is to say, the database and the mapping code are transformed into each other.

First add the Linq to SQL class, named Northwind.dbml, and then add a data table Customers to the class.

From the Northwind.designer.cs file of the figure, you can see

[System.Data.Linq.Mapping.DatabaseAttribute (Name= "Northwind")]

Public partial class NorthwindDataContext: System.Data.Linq.DataContext

{

[Table (Name= "dbo.Customers")]

Public partial class Customers: INotifyPropertyChanging, INotifyPropertyChanged

{

Private static PropertyChangingEventArgs

EmptyChangingEventArgs = new PropertyChangingEventArgs (String.Empty)

Private string _ CustomerID

You can see that NorthwindDataContext must inherit from the DataContext class, so it is supported by Linq.

Private void Form1_Load (object sender, EventArgs e) {NorthwindDataContext db = new NorthwindDataContext (); var c = from p in db.Customers select p; dataGridView1.DataSource = c;}

Run the effect diagram:

Thank you for reading, the above is the content of "how to understand Linq data and objects". After the study of this article, I believe you have a deeper understanding of how to understand Linq data and objects, and the specific use 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