NHibernate 中不等于运算符的命名查询

named query in NHibernate with not equal operator

NHibernate 抛出异常 sql 服务器不等于运算符 <>

<sql-query name="Select">
    <return alias="OrderStock" class="OrderStock"/>
select * from OrderStock WHERE dh.DATE_UNLOADED <> '1753-01-01'
</sql-query>

Name cannot begin with the '>' character

我们可以像这样用 &lt;&gt; 转义符号 <>

<sql-query name="Select">
    <return alias="OrderStock" class="OrderStock"/>
select * from OrderStock WHERE dh.DATE_UNLOADED &lt;&gt; '1753-01-01'
</sql-query>

或者我们可以使用 xml 原始文本转义 <![CDATA[ .... ]]>:

<sql-query name="Select">
    <return alias="OrderStock" class="OrderStock"/>
<![CDATA[
select * from OrderStock WHERE dh.DATE_UNLOADED <> '1753-01-01'
]]>
</sql-query>