This is a pretty simple question but I’m baffled by it. In the immediate window of Visual Studio, I see this:
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 awherefilter.<discriminator>withforce="true"attribute.<join>mapping that doesn’t match on one side and isn’t specified asoptional="true".<loader query-ref="...">for the entity.<filter>on the entity that has been enabled throughsession.EnableFilter.Proteinisn’t mapped to theProteintable.Proteinin different schemas, so NHibernate is queryingfoo.Proteinbut your sql is queryingdbo.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:
<property name="show_sql" value="true"/>and watching the console/logger.