Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your case, there will be a one-to-one mapping (there could be only one <code>MasterData</code> instance for a unique ID as well only one <code>OtherData</code>). In this case the <em>slave</em> entity <code>OtherData</code> has also have to reference to its <em>master</em> <code>MasterData</code></p> <pre><code>public class OtherData { public virtual long MasterDataID {get;set;} public virtual string OtherName {get;set;} public virtual MasterData MasterData {get;set;} } </code></pre> <p>Then we can follow this link to correctly map one-to-one: <a href="https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping" rel="nofollow">https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping</a></p> <h3>MasterData</h3> <pre><code>public MasterDataMap() { Id(x =&gt; x.MasterDataID).Column("MasterDataID") .GeneratedBy.gui.Sequence("MASTER_DATA_SEQ"); Map(x =&gt; x.Name).Column("Name"); HasOne(x =&gt; x.OtherData); } </code></pre> <h3>OtherData</h3> <pre><code>public OtherDataMap() { Id(x =&gt; x.MasterDataID, "MasterDataID") .GeneratedBy.Foreign("MasterData") Map(x =&gt; x.OtherName).Column("OtherName"); // change from x.Name HasOne(x =&gt; x.MasterData); } </code></pre> <p>What we are trying to achieve is to get this in XML</p> <h3>MasterData</h3> <pre><code> &lt;class name="MasterData" ...&gt; ... &lt;one-to-one cascade="delete-orphan" lazy="proxy" name="OtherData /&gt; .. &lt;/class&gt; </code></pre> <h3>OtherData</h3> <pre><code>&lt;class name="OtherData" ...&gt; &lt;id name="MasterDataID" column="MasterDataId"&gt; &lt;generator class="foreign"&gt; &lt;param name="property"&gt;MasterData&lt;/param&gt; &lt;/generator&gt; &lt;/id&gt; &lt;one-to-one name="MasterData" constrained="true" /&gt; ... &lt;/class&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload