One-to-many mappings in NHibernate-bidirectional correlation

Source: Internet
Author: User

The previous blog mentions a one-way association: nhibernate-one-to-many mappings-unidirectional correlation. This article is about two-way correlation.

The difference between two-way association and one-Way association is: Both sides can maintain the relationship, such as I query on either side, the other side of the information can also be queried, and other modifications deleted as long as the settings, also can. This is reflected in the code: because the previous one-way association is on dictionaryentity, it becomes a two-way association to Add an association map to dictiontypeentity and his corresponding XML file.


Dictionaryentity modified to:

#region Entity Properties///<summary>//Type///          </summary> public          virtual string type {Get;set;}          <summary>///type name///          </summary> public          virtual string TypeName  {get; set;}          <summary>///time stamp///          </summary> public          virtual string TimeStamp {get;set;}          <summary>///Operator user///          </summary> public          virtual string adduser{get; set;}           <summary>//        Dictionary Entity List Collection///        </summary> public        virtual ilist<dictionaryentity> Dictionaryentitys {get; set;}         


dictionaryentity the corresponding XML file:

<?xml version= "1.0" encoding= "Utf-8"? >


at this point, if we query the dictionaryentity information, want to know dictionarytypeentity value of the information, as long as in the DictionaryEntity.DictionaryType.Value can query out the values we want. If we want to save Dictionaryentity's letter,

We must first instantiate a dictionarytypeentity, and assigned to Dictionaryentity.dictionarytype. as follows:


Dictionarytypeentity endictionarytype=new dictionarytypeentity ();D ictionaryentity enDictionary=new Dictionaryentity (); endictionary.dictionarytype=endictionarytype;

This does not tell you that the "Object instantiation" error is not reported. This is not much simpler, to avoid the previous joint query what.

One-to-many mappings in NHibernate-bidirectional correlation

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.