Note that there are some explanatory texts on larger screens.

plurals
  1. PONo persister for... {SUBCLASS} NHibernate with Fluent NHibernate
    primarykey
    data
    text
    <p>How do I let NHibernate ignore extra properties of a subclass of my model?</p> <pre><code>class SuperModel { // hot I know { public Guid Id { get; private set; } public string FirstName { get; set; } } class SubModel : SuperModel { public string FavoriteColor { get; set; } } </code></pre> <p>I really only want to store the <code>SuperModel</code> data using my repository and use the <code>FavoriteColor</code> elsewhere, but I get </p> <pre><code>No persister for: SubModel </code></pre> <p>even though I save it with my repository as</p> <pre><code>void Store(SuperModel model) { using (var session = Session){ session.SaveOrUpdate(model); // &lt;&lt;&lt;&lt; The exception is thrown here } } </code></pre> <p>and some where else I use</p> <pre><code>void WhatToDo(SubModel model) { doSomething(model.FavoriteColor); } </code></pre> <p>And I use it as such</p> <pre><code>var model = new SubModel { FirstName = "Miranda", FavoriteColor = "Green" }; modelRepository.Store(model); someService.WhatToDo(model); </code></pre> <p>Any one know how I can fluently configure this? Thanks.</p> <p>FYI- implicit and explicit casting has no effect.</p> <p><strong>Edit</strong></p> <p>My mappings are like this</p> <pre><code>class SuperModelMap : ClassMap&lt;SuperModel&gt; { public SuperModelMap() { WithTable("SuperModels"); Id(x =&gt; x.Id); Map(x =&gt; x.FirstName); } } </code></pre> <p><strong>Edit 2</strong></p> <p>I figure/found out that I could do this, but in my database, I have to have a dummy table, which would just be inefficient. It works but there has to be a better way...</p> <p>In my SuperModelMap...</p> <pre><code>JoinedSubClass&lt;SubModel&gt;("SubModel", MapSubModel); private void MapSubModel(JoinedSubClassPart&lt;SubModel&gt; part) { // Leave this empty } </code></pre> <p><strong>Edit 3</strong> I'm closer, but I still get a different error on selection.</p> <p>I tried this.</p> <pre><code>DiscriminateSubClassesOnColumn("Id") .SubClass&lt;SubModel&gt;(m =&gt; { }); </code></pre> <blockquote> <p>InnerException {"Object with id: 5586b075-47f1-49c8-871c-9c4d013f7220 was not of the specified subclass: SuperUser (Discriminator was: '1000')"} System.Exception {NHibernate.WrongClassException}</p> </blockquote>
    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.
 

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