Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate child class mapping using DiscriminateSubClassesOnColumn issue
    primarykey
    data
    text
    <p>I have an issue with mapping, simplified my relationship looks like this. I have parent class:</p> <pre><code>public abstract class DocumentType { public virtual int Id { get; set; } public virtual string Name { get; set; } } </code></pre> <p>and two subclasses:</p> <pre><code>public class UploadedFileDocument : DocumentType { } public class ApplicationFormDocument : DocumentType { } </code></pre> <p>mapped like this:</p> <pre><code>public DocumentTypeMap() { Schema("Core"); Id(x =&gt; x.Id); Map(x =&gt; x.Name).Length(128).Not.Nullable(); DiscriminateSubClassesOnColumn("Type"); } public class UploadedFileDocumentMap : SubclassMap&lt;UploadedFileDocument&gt; { } public class ApplicationFormDocumentMap : SubclassMap&lt;ApplicationFormDocument&gt; { } </code></pre> <p>Then I have another entity with a FK to DocumentType, mapped like this:</p> <pre><code>public FileConversionMap() { Schema("Core"); Id(x =&gt; x.Id); References(x =&gt; x.Application).Not.Nullable(); References(x =&gt; x.DocumentType).Not.Nullable().Fetch.Select(); } </code></pre> <p>my issue is, when I retrieve rows from the DB like this:</p> <pre><code>Session.Query&lt;FileConversion&gt;().AsQueryable(); </code></pre> <p>all the rows come back with the <code>DocumentType</code> being of type <code>DocumentType</code>, not of the child type (ie the actual type of that property, ie. when i do <code>.GetType()</code>, either <code>UploadedFileDocument</code> or <code>ApplicationFormDocument</code>)</p> <p>Apologies if this is just me being dim. But how can I determine which type of <code>DocumentType</code> I have ... is my mapping wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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