Wednesday, 3 June 2009

Codesmith - NHibernate column mapping

When you have two or more foreign keys on a table linked to the same parent table, for example a product table could have a supplierid(fk) and a owningcompanyid(fk) both linking to the company table. The CodeSmith - Nhibernate generator would map these as Company1 and Company2, not very useful.

Get around this by adding an extended attribute to each of the columns in the database.

For example supplierid add the extended attribute cs_alias to each of the columns giving them a clearer name eg:

cs_alias Supplier (for the supplierid column)
cs_alias OwningCompany (for the owningcompanyid column)

Codesmith will then automatically rename the properties throughout the generated templates.