Is there any way to reuse NHibernate components (<component>) in more than one mapping? For example: an Address class in Employee and Customer classes - The only way to do this which I see now is to copy-paste the Address component mapping from one of the class mappings into another.
+1
A:
I haven't tried this with NHibernate but it worked with another OR Mapper that used XML configuration files. Create the component mapping in it's own XML file, then in the XML file that uses the component use an XML external entity to reference it. Here's a snippet from my Company mapping file:
<!DOCTYPE mappings [
<!ENTITY Address SYSTEM "MyCompany.MyApplication.Mappings.Address.xml">
]>
<mappings version="4.2" defaultNamespace="MyCompany.Model" defaultSchema="dbo">
<entity type="Company" table="Company" keyMember="CompanyId" keyType="Auto">
&Address;
Jamie Ide
2010-06-29 12:42:46
Thanks, Jamie, I'll try it
Serge
2010-06-30 07:41:26
A:
Apart from the solution that Jamie proposed, using code-based mappings provides better possibilities for reuse.
Currently, there are two such projects, Fluent NHibernate and ConfORM.
Diego Mijelshon
2010-06-29 14:48:00