Escaping a question mark character in a column name in NHibernate

点点圈 提交于 2019-12-24 06:37:55

问题


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

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