I find a recurring issue comes up often in my NHibernate projects. What I'd really like is a way of defining a property, collection or mapping fragment in a single mapping file, then add a reference to it in each of the classes that segment applies to. It's an issue of having to change many mapping files if I make a single code change.
I could see this done a couple ways:
1) Most of the time, this common behavior happens in a class hierarchy where I have an abstract class that isn't mapped. For this, maybe something like an <unmapped-subclass> element that doesn't get mapped to a table would make sense. Where all properties in this mapping get deferred to child mapped classes?
2) For the case of unmapped interfaces, implemented by classes in completely different hierarchies, maybe create a new element in a mapping file for the definition of mapping segments, and provide a way to reference those definitions in mapped classes.
#1 would probably be the cleaner and easier to implement, but #2 is a little more flexible.
Definitions for #2 could look something like:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Eg" namespace="Eg" default-lazy="false">
<mapping-def name="INotesContainer">
<set name="Notes" cascade="save-update">
<key column="ParentId" />
<one-to-many class="Note"/>
</set>
</mapping-def>
</hibernate-mapping>
and references could look like:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Eg" namespace="Eg" default-lazy="false">
<class name="SomeEntity" table="SomeEntities">
<id name="Id">
<generator class="guid.comb"/>
</id>
<mapping-ref name="INotesContainer"/>
</class>
</hibernate-mapping>
Does this sound useful to anyone else? Is there a better way to do what I'm looking for? If I felt like contributing code for something like this, is there anyone I should talk to besides Sergey for feedback on design before getting started?
Thanks.