NHibernate的:在模式导出强制方括号? [英] NHibernate: forcing square brackets in schema export?
问题描述
有没有办法告诉NHibernate在为MS SQL Server生成SQL模式导出时,对所有表名和列名使用方括号(如 [MyColumn]
)?我有一个遗留的数据库,使用保留名称的某些列和运行使用NH生成的SQL脚本抛出一个错误,因为它。
我想避免必须指定此
更新:我使用正确的方言:
MsSqlConfiguration.MsSql2008.ConnectionString(connectionString)
更新2:@UpTheCreek指出我在正确的方向 - 反引号,这帮助我在 NHibernate in Action 一书(第76页)中找到答案:
$ b
除了引用反引号中的所有表名和列名外,没有办法强制NHibernate在任何地方使用带引号的标识符。
$ b $ pre $ SchemaMetadataUpdater.QuoteTableAndColumns($)
/ code>
(构建SessionFactory之前)
<这将自动引用所有保留的名字。Is there a way to tell NHibernate to use square brackets for all table and column names (like
[MyColumn]
) when generating the SQL schema export for MS SQL Server? I have a legacy database that uses reserved names for certain columns and running the SQL script generated using NH throws an error because of it.I want to avoid having to specify this separately for each column.
UPDATE: I'm using the correct dialect:
MsSqlConfiguration.MsSql2008.ConnectionString(connectionString)
UPDATE 2: @UpTheCreek pointed me in the right direction - backticks, which helped me find the answer in the "NHibernate in Action" book (p. 76):
There is no way, apart from quoting all table and column names in backticks, to force NHibernate to use quoted identifiers everywhere.
解决方案Easier approach:
SchemaMetadataUpdater.QuoteTableAndColumns(config)
(Before building SessionFactory)
That will quote all the reserved names automatically.
这篇关于NHibernate的:在模式导出强制方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!