Http://u.115.com/file/f2a1ed628e demo
Demonstration highlights
To establish a ing between two object classes, you only need to correctly set the three attributes of columnattribute: storage, thiskey, and otherkey. If the field of the object class is used rather than the attribute, even the storage attribute can be omitted.
No matter how the ing relationship is established, the most fundamental purpose is to obtain some other objects associated with an object. For example, after obtaining a customer object, we obtain all the order objects associated with it through a set attribute of the customer object. Therefore, if you want to obtain the associated data successfully by using LINQ to SQL, you must provide at least three pieces of information:
1. Data Retrieval conditions. For example, the Order record of the customer to be retrieved.
2. From which table to search. For example, these order records are stored in the data table of the database.
3. Use the search condition to compare the data column. For example, the customer ID is stored in the column of the data table that stores the order record.
When this information is met, the associated data can be correctly obtained.
The thiskey attribute is used to provide the data to be retrieved. This attribute value is actually a key-Value Attribute of the object class, and the attribute value of this key-Value Attribute specifies the data to be retrieved.
Otherkey is used to specify the column to be judged by conditions in the WHERE clause. This attribute value is also a key-Value Attribute of the object class, however, this time, the attribute value of this key-value property is not required, but the name of the data column mapped to this key-value property is required.
As for the data table from which to retrieve the associated data, this determines the object type to be obtained. It is actually the data table mapped by the object class.