Sunday, 4 October 2009

NHibernate and quoted identifiers

If you have a column or table name that is a reserved word or which contains spaces etc. you can force NHibernate to use quoted identifiers by using a back tick in the table/column name:

<class name="LineItem" table="`Line Item`">
    <id name="Id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="ItemNumber" column="`Item #`"/>
    ...
</class>