Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The syntax may have changed in FNH since Erik's post, but his example is right on target. Here's some code I used based on Erik's post to work through FNH the two FNH subclass strategies I know of right now (SubClass (the commented out code below, and JoinedSubClass). As an aside, I've seen other names used to describe the same strategies, including in NHibernate docs, which is a bit confusing when this is new to you. (<a href="https://www.hibernate.org/hib_docs/nhibernate/html/inheritance.html" rel="nofollow noreferrer">https://www.hibernate.org/hib_docs/nhibernate/html/inheritance.html</a>). </p> <pre><code>// Domain classes public class Animal : Entity { public virtual string Name { get; set; } public virtual string Unwanted { get; set; } } public class Cat : Animal { public virtual int WhiskerLength { get; set; } public virtual int ClawCount { get; set; } } public class Dog : Animal { public virtual int TailWagRate { get; set; } } public class Boxer : Dog { public string DroolBucket { get; set; } } public class AnimalMapJoinedSubclassOverride : IAutoMappingOverride&lt;Animal&gt; { public void Override(AutoMap&lt;Animal&gt; mapping) { mapping.Map(x =&gt; x.Name); mapping.IgnoreProperty(x =&gt; x.Unwanted); mapping.JoinedSubClass("CatId", CatMap.AsJoinedSubClass()); mapping.JoinedSubClass("DogId", DogMap.AsJoinedSubClass()); //mapping.DiscriminateSubClassesOnColumn("Type") // .SubClass&lt;Cat&gt;("CatId", CatMap.AsSubClass()) // .SubClass&lt;Dog&gt;("CatId", DogMap.AsSubClass()); } } public class CatMap { public static Action&lt;JoinedSubClassPart&lt;Cat&gt;&gt; AsJoinedSubClass() { return part =&gt; { part.Map(x =&gt; x.ClawCount).Not.Nullable(); part.Map(x =&gt; x.WhiskerLength).Not.Nullable(); }; } public static Action&lt;SubClassPart&lt;Cat&gt;&gt; AsSubClass() { return part =&gt; { part.Map(x =&gt; x.ClawCount); part.Map(x =&gt; x.WhiskerLength); }; } } public class DogMap { public static Action&lt;JoinedSubClassPart&lt;Dog&gt;&gt; AsJoinedSubClass() { return sub =&gt; { sub.Map(x =&gt; x.TailWagRate).Not.Nullable(); }; } public static Action&lt;SubClassPart&lt;Dog&gt;&gt; AsSubClass() { return sub =&gt; { sub.Map(x =&gt; x.TailWagRate); }; } } public class BoxerMap { public static Action&lt;JoinedSubClassPart&lt;Boxer&gt;&gt; AsJoinedSubClass() { return sub =&gt; { sub.Map(x =&gt; x.DroolBucket); }; } public static Action&lt;SubClassPart&lt;Boxer&gt;&gt; AsSubClass() { return sub =&gt; { sub.Map(x =&gt; x.DroolBucket); }; } } </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