Fluent NHibernate Column Mapping with Reserved Word

怎甘沉沦 提交于 2019-12-17 20:44:33

问题


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?


回答1:


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

"`File`"

As @Astaar says, the full syntax is:

Map(x => x.File).Column("`File`");



回答2:


To be perfectly clear, the exact syntax would be

Map(x => x.File).Column("`File`");



回答3:


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);


来源:https://stackoverflow.com/questions/1545120/fluent-nhibernate-column-mapping-with-reserved-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!