I have a SQL Server table containing hierarchial categories, TipCategories. It has an Id field and a ParentId field which may be null. There is also an int field named DisplayRank that is used to affect the sort of categories for display. So the abridged table schema looks like:
Code:
TABLE TipCategories (
Id uniqueidentifier not null,
ParentId uniqueidentifier null,
DisplayRank int not null)
The mapping is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="Core" namespace="Core">
<class name="TipCategory" table="TipCategories">
<id name="Id" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<many-to-one name="ParentCategory" column="ParentId" class="TipCategory" />
<property name="DisplayRank" />
</class>
</hibernate-mapping>
I create the following query:
Code:
select max(category.DisplayRank) from TipCategory category where category.ParentCategory = :parentCategory
And pass null in as a parameters, qualifying it as a TipCategory type. NHibernate produces the following SQL:
Code:
select max(tipcategor0_.DisplayRank) as x0_0_
from TipCategories tipcategor0_
where (tipcategor0_.ParentId = @p0)
It binds null to @p0, and the result of this query is NULL. However, if it had been using the "is null" clause, I would get the numeric result I expected.
Is this a bug or am I doing something wrong?
-mt