Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate table per class hierarchy multiple tables mapping problem
    primarykey
    data
    text
    <p>I've got a problem with fluent nhibernate table per class hierarchy mapping. I've got 2 domain objects, container (baseclass) and album (subclass). Album only contains a constructor. Container dervies from EntityWithTypedId from Sharp Architect. EntityWithTypedId provides the key of type Guid (the name is ContainerId).</p> <pre><code>public class Container : EntityWithTypedId&lt;Guid&gt; { public Container() { } protected Container(Guid userId) : this() { UserId = userId; } public virtual int Type { get; set; } public virtual Guid UserId { get; set; } } public class Album : Container { public Album() : base() { Type = (int)ContainerType.Album; } public Album(Guid userId) : base(userId) { Type = (int)ContainerType.Album; } } </code></pre> <p>I want all the domain objects to be saved in a single table called "Containers". I've got a mapping file for Container:</p> <pre><code>public class ContainerMap : IAutoMappingOverride&lt;Container&gt; { public void Override(AutoMap&lt;Container&gt; mapping) { mapping.DiscriminateSubClassesOnColumn&lt;int&gt;("Type"); } } </code></pre> <p>NHibernate assumes 2 tables are used. The table "Containers" is mapped as expected, but NHibernate assumes theres another table "Album" only containing an Id called "Container" which is equal to ContainerId in table "Containers". How can i change the mapping so the table "Album" isn't needed? </p> <p>If i provide a mapping class for Album i get a mapping error even if the album mapping is empty: FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.</p> <ul> <li><p>Database was not configured through Database method.</p> <p>----> System.ArgumentException : Object of type 'FluentNHibernate.AutoMap.AutoMap<code>1[Core.Album]' cannot be converted to type 'FluentNHibernate.AutoMap.AutoMap</code>1[Core.Container]'.</p></li> </ul> <p>Thanks!</p> <p>/Marcus</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