When an field name conflict with some database dialect keywords, NHibernate offer a syntax in the mapping to escape the identifier so that the mapping can behave properly: quote the identifier with the "`" sign.
Unfortunately the dialect implementer is not obliged to espose a list of keywords that needs to be escaped, so I decided to put something in the NHModeller syntax to achieve the same results.
This is the sample entity:
NHModel{ Entity From { @Select:int @Count:int Another:string(30) } in @From }
The sign @ forces the correct escape generation in the mapping:
<?xml version='1.0' ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyTest" namespace="MyTest.Entities"> <class name="From" table="`From`"> <id name="Id" column="Id" access="field.camelcase-underscore"> <generator class="native" /> </id> <property name="Select" column="`Select`" type="System.Int32" not-null="true" /> <property name="Count" column="`Count`" type="System.Int32" not-null="true" /> <property name="Another" column="Another" type="String" not-null="true" length="30" /> </class> </hibernate-mapping>
and will issue the correct db script ( ie MsSql2005 ):
if exists (select * from dbo.sysobjects where id = object_id(N'[From]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [From]; create table [From] ( Id INT IDENTITY NOT NULL, [Select] INT not null, [Count] INT not null, Another NVARCHAR(30) not null, primary key (Id) );
Remember Me
a@href@title, b, strike, strong
E-mail
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.