views:

26

answers:

1

We have a bunch of lookup tables that all share the same columns (ID,Code,Description, etc) and my co-worked just asked me if we could build a generic lookup.hbm.xml mapping file and use it as a base for all the other lookup tables. Does nhibernate support include files, or some other way to reference a common chunk of XML? I understand that Fluent supports inheritance in the mapping classes, but unfortunately switching mapping technologies is not an option for us.

+2  A: 

Yes, you can using XML external entities. Put the common fields in an XML file and reference them in other XML files using !ENTITY. For example:

<!DOCTYPE mappings [
  <!ENTITY Address SYSTEM "xxx.Address.xml">
]>

In the XML for the NHibernate map you import this using

&Address;

The full namespace (path) to the file needs to be used. I have noticed in Visual Studio (2008 at least) that if there is an error in any file and you have an XML file open that uses an external reference, it will report an error on that also.

Jamie Ide