Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of LINQ to SQL Mapping column

Shulou Source: shulou.com Published: 2022-06-02 09:15:14 09月15日 Update

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!

Tags: Attributes data databases fields entities articles examples analysis content only annotations associations special similar for this not much information just most of the examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Linux Xiaomi OPPO Reno