views:

140

answers:

2

How do I escape keyword conflicts when NHibernate generates my column names using FluentNHibernate?

NHibernate generated this for me and "Key" is a conflict.

create table Setting (
       Key NVARCHAR(MAX) not null,
       Value NVARCHAR(MAX) null,
       primary key (Key)
)
A: 

Try this:

create table Setting (
       [Key] NVARCHAR(MAX) not null,
       Value NVARCHAR(MAX) null,
       primary key (Key)
)

SQL Server allows you to escape reserved words by putting square brackets around the text.

Andrew Hare
How do I tell NHiberate to do that?
Daniel A. White
Put names (of tables, fields) in backticks: `Setting`, `Key`. In fluent, you may want conventions to do that.
queen3
@queen3 how do i do that for all of them?
Daniel A. White
Oops, SO ate my backticks ;-) Anyway, I think FNH should use backticks everywhere by default according to http://www.mail-archive.com/[email protected]/msg00683.html, but it used to change so often...
queen3
@queen3 i think its changed since then.
Daniel A. White
Read here: http://wiki.fluentnhibernate.org/Convention_shortcut.
queen3
You may also want to override, for example, IPropertyConvention to setup column (property) names. The topic is already described in FNH wiki.
queen3
A: 

I was able to create conventions.

Daniel A. White