Nhib one-to-multiple ing
In nhib, The ing file corresponds to the relationship in the database table. All Nhibernate instances also have one-to-one ing, one-to-many ing, and many-to-many ing. First, let's look at one-to-many ing. one-to-many ing means that the relationship between two tables in the database is one-to-many. For example, the relationship between students and classes is one-to-many, one class has multiple students, and one student belongs to only one class. The dictionary type and dictionary table are also one-to-many relationships. Use the dictionary type and dictionary table as an example:
One-to-Multiple Association ing can be divided into one-to-one and two-way. One-to-one ing maintains their relationships on one side, and two-way ing maintains relationships on both sides. First, let's look at the one-to-many Association ing.
Dictionary type: DictionTypeEntity and dictionary entity:
Public class DictionaryEntity {////// ID ///Public virtual Guid ID {get; set ;}////// Key ///Public virtual string Key {get; set ;}////// Key value ///Public virtual string Value {get; set ;}////// Type ///Public virtual string Type {get; set ;}////// Timestamp ///Public virtual string TimeStamp {get; set ;}////// Operation user ///Public virtual string AddUser {get; set ;}////// Remarks, description ///Public virtual string Remark {get; set ;}}
////// This entity class and database table 't_ DictionaryManage './//Public class DictionaryTypeEntity {# region object attributes ////// Type ///Public virtual string Type {get; set ;}////// Type name ///Public virtual string TypeName {get; set ;}////// Timestamp ///Public virtual string TimeStamp {get; set ;}////// Operation user ///Public virtual string AddUser {get; set ;}# endregion ////// Dictionary Object list set ///Public virtual IList
DictionaryEntitys {get; set ;}}
Hbm. xml file corresponding to dictionary type DictionTypeEntity:
Hbm. xml file corresponding to dictionary entity DictionEntity:
In this way, all records of this type in the dictionary table are also queried when you query a dictionary type. This shows that two tables are not used for joint queries.
Nhibernate supports lazy loading. If lazy = true is set, the corresponding records in the dictionary table will not be queried at the beginning, and will be found only when they are actually used, in this way, we can improve some efficiency.