问题
I have an entity with a property whose column name contains a question mark. How do I map the column name so that an HQL query will correctly generate SQL with the column name wrapped appropriately (i.e. [] for SQL Server) instead of substituting a parameter for the question mark? I have tried wrapping the column name in backticks or square brackets but this doesn't work.
回答1:
Backticks work fine for me. Remember to use them only in the mapping file, not in the HQL:
<property name="Data1" column="`Data1?`" />
This query:
session.CreateQuery("select Data1 from Foo").List();
Results in this SQL:
select foo0_.[Data1?] as col_0_0_
from Foo foo0_
Update: this is a bug in NHibernate 3.1. Jira issue created
来源:https://stackoverflow.com/questions/5805617/escaping-a-question-mark-character-in-a-column-name-in-nhibernate