Will the following NHibernate interface mapping work?

Posted by Ben Aston on Stack Overflow See other posts from Stack Overflow or by Ben Aston
Published on 2010-04-19T15:43:11Z Indexed on 2010/04/19 17:13 UTC
Read the original article Hit count: 320

I'd like to program against interfaces when working with NHibernate due to type dependency issues within the solution I am working with.

SO questions such as this indicate it is possible.

I have an ILocation interface and a concrete Location type. Will the following work?

HBM mapping:

<class name="ILocation" abstract="true" table="ILocation">
  <id name="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
    <column name="LocationId" />
    <generator class="guid" />
  </id>       
        <union-subclass table="Location" name="Location">
                <property name="Name" type="System.String"/>
        </union-subclass>
</class>

Detached criteria usage using the interface:

var criteria = DetachedCriteria.For<ILocation>().Add(Restrictions.Eq("Name", "blah"));            
var locations = criteria.GetExecutableCriteria(UoW.Session).List<ILocation>();

Are there any issues with not using the hilo ID generator and/or with this approach in general?

© Stack Overflow or respective owner

Related posts about nhibernate-mapping

Related posts about nhibernate