Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For this to work as you expect, you'll need to have a base class for <code>Automobile</code>, <code>Business</code> and <code>Property</code> classes. Let's call it <code>LeaseSubject</code>. Presumably, you already have something like that in your domain model.</p> <p>Your Utility class should have only one property, instead of three you have now:</p> <pre><code>public virtual LeaseSubject LeaseSubject { get; set; } </code></pre> <p>This way you not only have easier mapping, but also promote the maintainability of your code. What if at some later time you decide to have one more lease subject, i.e. <code>Yacht</code>? Instead of adding another <code>Yacht</code> property to your Utility class, you just need to inherit from <code>LeaseSubject</code>, and it could be contained within the <code>LeaseSubject</code> property on <code>Utility</code> class.</p> <p>Now you could map your Utility simply as:</p> <pre><code>public UtilityMap() { // Other mappings... References(x =&gt; x.LeaseSubject, "LeaseRefId"); } </code></pre> <p>For mapping Automobile, Business and Property classes, you would use one of three available NHibernate <a href="http://www.nhforge.org/doc/nh/en/index.html#inheritance-strategies" rel="nofollow">inheritance strategies</a>:</p> <ul> <li>table per class hierarchy</li> <li>table per subclass</li> <li>table per concrete class</li> </ul> <p>For <a href="https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping" rel="nofollow">FluentNHibernate</a> inheritance mapping, take a look <a href="http://www.codeproject.com/Articles/232034/Inheritance-mapping-strategies-in-Fluent-Nhibernat" rel="nofollow">here</a>.</p> <p>Since you already have separate tables, I believe the correct strategy for your case would be Table per concrete class. You can find some more info in this <a href="http://ang3lfir3.wordpress.com/2009/08/04/table-per-clas%E2%80%A6ent-nhibernate/" rel="nofollow">article</a>.</p>
 

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