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?
You need to put ` on both sides, like this:
"`File`"
As @Astaar says, the full syntax is:
Map(x => x.File).Column("`File`");
To be perfectly clear, the exact syntax would be
Map(x => x.File).Column("`File`");
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);