[英]Why would NHibernate.ISession.CreateQuery return something different from CreateSQLQuery when CacheMode=Ignore?
This is a pretty simple question but I'm baffled by it. 这是一个非常简单的问题,但我对此感到困惑。 In the immediate window of Visual Studio, I see this: 在Visual Studio的即时窗口中,我看到以下内容:
session.CacheMode
Ignore
session.CreateQuery("SELECT COUNT(*) FROM Protein").List()
Count = 1
[0]: 0
session.CreateSQLQuery("SELECT COUNT(*) FROM Protein").List()
Count = 1
[0]: 6
There could be several causes for something like this, check your mappings for the following: 可能有多种原因导致这种情况,请检查以下映射:
<class>
mapping with a where
filter. 具有where
过滤器的<class>
映射。 <discriminator>
with force="true"
attribute. 具有force="true"
属性的<discriminator>
。 <join>
mapping that doesn't match on one side and isn't specified as optional="true"
. 一侧不匹配且未指定为optional="true"
的<join>
映射。 <loader query-ref="...">
for the entity. 实体的自定义<loader query-ref="...">
。 <filter>
on the entity that has been enabled through session.EnableFilter
. 通过session.EnableFilter
启用的实体上的<filter>
。 Protein
isn't mapped to the Protein
table. Protein
类未映射到Protein
表。 Protein
in different schemas, so NHibernate is querying foo.Protein
but your sql is querying dbo.Protein
. 您可能在不同的模式中有2个名为Protein
表,因此NHibernate正在查询foo.Protein
但是您的sql正在查询dbo.Protein
。 After that it starts to get more esoteric such as using custom dialects, entity tuplizers, etc. 之后,它开始变得更加神秘,例如使用自定义方言,实体修饰符等。
One simple way to see what is going on is to look at the SQL being issued, you can do this by: 查看正在发生的情况的一种简单方法是查看发出的SQL,您可以通过以下方法执行此操作:
<property name="show_sql" value="true"/>
and watching the console/logger. 设置<property name="show_sql" value="true"/>
并查看控制台/记录器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.