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 i开发者_StackOverflow社区nto another.
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;
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.
Unfortunally not. I really need that feature too ;)
精彩评论