16

I've read that using a back tick ` should allow for using of reserved words. I'm using SQL Server and Fluent NHibernate and have a column name "File". If I map it with

"`File" 

it tries using

[Fil]

so it's adding the brackets correctly, but dropping the "e" from the end. If I map it as

"`Filee"

it uses

[File]

correctly.

Am I doing something wrong or is this a bug in NHibernate or Fluent Nhibernate?

Josh Close
  • 22,935
  • 13
  • 92
  • 140
  • Have you tried with out doing any thing with the fluentNHibernate. If you export the hbm file fluentNHibernate will write table="`File`" for you. – Aaron Fischer Oct 09 '09 at 23:06

3 Answers3

24

You need to put ` on both sides, like this:

"`File`"

As @Astaar says, the full syntax is:

Map(x => x.File).Column("`File`");
Matthew Talbert
  • 5,998
  • 35
  • 38
5

To be perfectly clear, the exact syntax would be

Map(x => x.File).Column("`File`");
Astaar
  • 5,858
  • 8
  • 40
  • 57
5

There are non manual configuration options for this as covered here: NHibernate: forcing square brackets in schema export?

as well as an alternative: Fluent NHibernate and PostgreSQL, SchemaMetadataUpdater.QuoteTableAndColumns - System.NotSupportedException: Specified method is not supported

E.g. SchemaMetadataUpdater.QuoteTableAndColumns(cfg) which in FluentNhibernate would look something like

var config = Fluently.Configure()
   ...
   ...
   .ExposeConfiguration(cfg => SchemaMetadataUpdater.QuoteTableAndColumns);
Community
  • 1
  • 1
Daniel
  • 8,133
  • 5
  • 36
  • 51
  • 1
    I think this solution is better because it's a one time setting instead of adding all new column names being reserverd words specifically in each map. – Sebastian Ballarati Oct 05 '17 at 20:56