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

Example Analysis of LINQ to SQL Mapping column

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

Share

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

Editor to share with you the example analysis of LINQ to SQL mapping column, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

LINQ to SQL mapping table

In LINQ to SQL, database tables are represented by entity classes. The entity class is similar to any other class you might create, except that the entity class is annotated with special information that associates the class with the database table. You need to make this annotation by adding a custom attribute (TableAttribute) to the class declaration.

Only instances of classes declared as tables (that is, entity classes) can be saved to the database.

[Table (Name = "Student")] public class Customerzz {}

LINQ to SQL mapping column

In addition to associating a class with a table, you need to specify fields or properties to represent database columns. To do this, LINQ to SQL defines the ColumnAttribute attribute.

Only the fields and properties of the LINQ to SQL mapped column can be persisted to the database, and can only be retrieved from the database. Fields and properties that are not declared as columns are treated as transient parts of the application logic.

[Table (Name = "Student")] public class Customerzz {[Column (IsPrimaryKey = true)] public int ID {get; set;} [Column] public string StuName {get; set;} [Column] public bool Sex {get; set;} [Column] public int Age {get; set;}} above are all the contents of the article "sample Analysis of LINQ to SQL Mapping columns". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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