nHibernate 4.1.4 未引用匹配保留关键字的 table 名称

nHibernate 4.1.4 is not quoting table name that matches reserved keyword

我正在使用 nHibernate 4.1.4 MappingByCode。我的方言是

public class Dialect : NHibernate.Dialect.MsSql2012Dialect
{
    protected override void RegisterKeywords()
    {
        base.RegisterKeywords();
        RegisterKeyword("user");
    }
}

我的配置正在设置 config.SetProperty(环境.Hbm2ddlKeyWords, "keywords");

我有一个名为 table 的用户。

SQL 抛出错误 table name 用户无效。 nHibernate 无法将其括在方括号中。

有什么想法吗?

关键字用于不同的目的...

我们需要的是临时 table 名称转义

5.3. SQL quoted identifiers

You may force NHibernate to quote an identifier in the generated SQL by enclosing the table or column name in back-ticks in the mapping document. NHibernate will use the correct quotation style for the SQL Dialect (usually double quotes, but brackets for SQL Server and back-ticks for MySQL).

<class name="LineItem" table="`Line Item`">
    <id name="Id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="ItemNumber" column="`Item #`"/>
    ...
</class>

即在映射中,我们需要转义 table name:

"`user`"

关键字,在方言配置中定义,在使用自定义 sql 语句时将有助于 NH 解析器。例如。在 formulassubselects