In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of LINQ to SQL mapping relationship, which is very detailed and has certain reference value. Friends who are interested must finish it!
LINQ to SQL mapping relation
In LINQ to SQL, database associations, such as foreign key to primary key relationships, are represented by applying the AssociationAttribute attribute.
You can encode any data relationship that is always the same as an attribute reference in your entity class. For example, in the Northwind sample database, because customers usually place orders, there is always a relationship between customers and their orders in the model.
LINQ to SQL defines the AssociationAttribute attribute to help represent such relationships. This property is used with the EntitySet and EntityRef types to represent what will be a foreign key relationship in the database.
◆ EntitySet: provides deferred loading and relationship maintenance for aggregators of one-to-many and one-to-one relationships in LINQ to SQL applications.
◆ EntityRef: provides deferred loading and relationship maintenance for a single instance of an one-to-many relationship in a LINQ to SQL application.
Most relationships are one-to-many, as will be reflected in the examples later in this topic. You can also represent one-to-one and many-to-many relationships as follows:
◆ one-to-one: this type of relationship is represented by adding EntitySet to both parties.
For example, suppose you have a Customer-SecurityCode relationship that is created so that the customer's security code cannot be found in the Customer table and can only be accessed by authorized people.
◆ many-to-many: in a many-to-many relationship, the primary key of a linked table (also known as a join table) is usually composed of foreign keys from the other two tables.
For example, suppose you have an Employee-Project many-to-many relationship formed by using the linked table EmployeeProject. LINQ to SQL requires that this relationship be modeled with three classes: Employee, Project, and EmployeeProject. In this case, changing the relationship between Employee and Project seems to require updating the primary key EmployeeProject. However, the modeling approach in this case * is to delete the existing EmployeeProject and then create a new EmployeeProject.
LINQ to SQL mapping relation Demo
[Table (Name = "Student")] public class Student {[Column (IsPrimaryKey = true)] public int ID; [Column] public string StuName; [Column] public bool Sex; [Column] public int Age; private EntitySet _ Scores; [Association (Storage = "_ Score", OtherKey = "StudentID")] public EntitySet Scores {get {return this._Scores;} set {this._Scores.Assign (value) } [Table (Name = "Score")] public class Score {[Column (IsPrimaryKey = true)] public int ID; [Column] public int StudentID; [Column] public float Math; [Column] public float Chinese; [Column] public float English; [Column] public DateTime Times;} these are all the contents of the article "sample Analysis of LINQ to SQL Mapping". Thank you for reading! Hope to share the content to help you, more related 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.