Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate can not retrieve typeof a derived class correctly
    text
    copied!<p>Hello<br> Short and to the point, I have 3-level inheritance :</p> <pre><code>public class JobBase { virtual public Guid Id { get; set; } // Some properties here } public class Job:JobBase { // Some properties here } public class JobTypeX : Job { // Some properties here } public class JobTypeY : Job { // Some properties here } </code></pre> <p>Mappings :</p> <pre><code>public class JobBaseMap : ClassMap&lt;JobBase&gt; { public JobBaseMap() { Id(p =&gt; p.Id); //other mappings } } public class JobMap : SubclassMap&lt;Job&gt; { public JobMap() { KeyColumn("JobBaseId"); //other mappings } } public class JobTypeXMap : SubclassMap&lt;JobTypeX&gt; { public JobTypeXMap() { KeyColumn("JobBaseId"); //other mappings } } public class JobTypeYMap : SubclassMap&lt;JobTypeY&gt; { public JobTypeYMap() { KeyColumn("JobBaseId"); //other mappings } } </code></pre> <p>Another class which uses Job </p> <pre><code>public class Person { virtual public Guid Id { get; set; } virtual public Job MyJob { get; set; } } </code></pre> <p>well, when I want to add a new Person I write somthing like :</p> <pre><code> Person person = new Person(); //set other properties //jobId can be either JobTypeX's id or JobTypeY's id person.MyJob = Repository&lt;Job&gt;.Get(jobId); //surely, one of conditions is true if (person.MyJob is JobTypeX) { //do something } else if (person.MyJob is JobTypeY) { //do sth else here } Repository&lt;Person&gt;.Save(person); </code></pre> <p>So far so good. It loads the same data by the code below :</p> <pre><code> Person person = Repository&lt;Person&gt;.Get(personId); </code></pre> <p>Although all the values of <strong>person.MyJob</strong> is correct when person is loaded, it cannot recognize the Job type anymore :</p> <pre><code> if (person.MyJob is JobTypeX) // false { //do something } else if (person.MyJob is JobTypeY) // false { //do sth else here } </code></pre> <p>There are a few ways to get rid of this problem. For example, I can check whether JobBaseId is available in table JobTypeX or JobTypeY. but I guess something should be wrong somewhere!</p> <p>do I miss something? any idea?</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