Nhib one-to-multiple ing

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.