Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent nhibernate automap subclasses from different assemblies
    text
    copied!<p>What I need to do is automap subclasses of my abstract page class. I need to find them in a list of assemblies that I get a runtime (at the initialization stage). I don't have any reference to the assemblies from the assembly of my mappings. </p> <p>My page class looks something like this:</p> <pre><code>public abstract class Page : EntityBase { public virtual int Id { get; protected set; } public virtual Page Page { get; set; } //Other properties } </code></pre> <p>My mappings looks like this:</p> <pre><code>var persistenceModel = new AutoPersistenceModel(); _assemblies.ForEach(x =&gt; persistenceModel.AddEntityAssembly(x)); persistenceModel.Setup(x =&gt; { x.SubclassStrategy = y =&gt; SubclassStrategy.Subclass; x.DiscriminatorColumn = y =&gt; "Type"; }) .IncludeBase(typeof(Page)) .OverrideAll(x =&gt; x.IgnoreProperties(y =&gt; typeof(Page) .IsAssignableFrom(y.ReflectedType) &amp;&amp; y.ReflectedType != typeof(Page))) .Where(y =&gt; typeof(EntityBase).IsAssignableFrom(y)); </code></pre> <p>_assemblies is a list of assemblies to search for mappable entities in. It contains the assembly of my page class as well as one or more other assemblies that all have a reference to the base assembly (the one with my page class).</p> <p>When I add a class that inherits from my page class to the same assembly as my page class all works fine and its mapped appropriately. But if I add one to one of the other assemblies that are loaded at runtime I get problems. I get this error:</p> <p>"Tried to add many-to-one 'Page' when already added."</p> <p>It finds the class but for some reason tries to map it as Page or something. But the page class is already mapped so I get that error. That is my guess. Does anyone know if I can work around this in any way? Or know a solution?</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