I'm trying to map inheritance with discriminator, but subclasses don't have discriminator value. How to solve it using AutoMappings?
Domain objects are as following:
public abstract class Item : GuidIdentityEntity {
public virtual string Name { get; set; }
}
public class Product : Item {}
public class RawMaterial : Item {}
Configuration looks like:
AssemblyOf<Item>()
.IgnoreBase<GuidIdentityEntity>();
.IncludeBase<Item>();
.Setup(setup => {
setup.DiscriminatorColumn = type => "Discriminator";
setup.IsDiscriminated = type => type == typeof(Item);
setup.SubclassStrategy = type => (type == typeof(Item))
? SubclassStrategy.Subclass
: SubclassStrategy.JoinedSubclass;
});
Outcome of mappings are:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Solution.Core.Products.Item, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" table="`Item`">
<id name="Id" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="guid.comb" />
</id>
<discriminator type="String">
<column name="Discriminator" />
</discriminator>
<property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Name" />
</property>
<subclass name="Solution.Core.Products.RawMaterial, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" />
<subclass name="Solution.Core.Products.Product, Solution.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2e5ef41be3839ad7" />
</class>
</hibernate-mapping>