NHibernate Tip: Escaping column names

by benl

Another quick NH tip. When escaping column names in mapping files, remember to use backticks i.e. `ColumnName` and not square brackets a la SQL Server i.e. [ColumnName]. NHibernate replaces backticks at runtime with the correct escaping sequence for your chosen database dialect thus aiding portability to other RDBMs.

While we're on the subject of databases and NHibernate, another little-known tip (for SQL Server) which a colleague mentioned to me: When specifying tables in your mapping files, prefix them with the database name and owner i.e. "Pubs.dbo.Authors". For a potentially significant performance increase when issuing complex queries via NHibernate. Although this does affect database portability slightly 🙂

Advertisements