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