I have a class base on my map, it inherited two new classes
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Business" namespace="Business.Test">
<class name="BaseExample" table="base_example" abstract="true" discriminator-value="0">
<id name="Id" column="id" type="Int64" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="domain" type="Int16" not-null="true" force="true" />
....
....
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Business" namespace="Business.Test">
<subclass name="Example1" extends="BaseExample" discriminator-value="1">
....
....
</subclass>
</hibernate-mapping>
everything works fine, but if I ask for that field, for example:
var Clients = ClientFactory.GetAll().Where(c => c.UserData.BaseExample.Domain == 1);
throw this exception: Exception Message: could not resolve property: Domain of: Business.Entities.BaseExample
how can tell if it is of one class or another?
Discriminators are meant to be used behind-the-scenes from NHibernate (see Rippo’s example). The idea is that you query the class and the appropriate discriminator from that class’s mapping is injected into the query.
However, if for some reason you need that information in a property it is valid to include it as a property. That means
it is important that you declare the property as readonly (
update="false" insert="false") since this is a column managed completely by nhibernate.