I have a table in a reporting database that I want to query out of.  There 
is no primary key and only two foreign keys with a composite unique index.

Company Name, Group, Measure A, Measure B, ....

The possible values are:

Company Name = Acme, Group = null, Measure A = value at org level
Company Name = Acme, Group = Foo, Measure A = value at org's foo level

The mapping currently generates the correct query (as seen through NH Prof) 
but returns null when trying to get the object from the query class:

  <class mutable="false" name="NetworkStatistics" table="NetworkStatistics">
    <composite-id>
      <key-property name="CompanyName" type="string">
        <column name="Company_Name" />
      </key-property>
      <key-many-to-one name="Group" class="Group" not-found="ignore">
        <column name="Group_Id" />
      </key-many-to-one>
    </composite-id>
    <property name="MeasureA" type="decimal">
      <column name="Measure_A" />
    </property>
    <property name="MeasureB" type="decimal">
      <column name="Measure_B" />
    </property>
    <many-to-one class="Group" name="Group">
      <column name="Group_Id" not-null="false" />
    </many-to-one>
  </class>

The query code path is as follows:

var query = session.CreateCriteria<NetworkStatistics>()
        .Add(Restrictions.Eq("CompanyName", parameters.CompanyName));
...
query.Add(Restrictions.IsNull("DeviceGroup"));
...
var data = query.UniqueResult<NetworkStatistics>();

I see NH create the property query which results in a row being returned:

SELECT this_.Company_Name         as Company1_10_0_,
       this_.Group_Id             as Group2_10_0_,
       this_.Measure_A as Measure3_10_0_,
       this_.Measure_B      as Measure4_10_0_
FROM   TFT_Network_Statistics this_
WHERE  this_.Company_Name = 'Acme'
       and this_.Group_Id is null

But the output of UniqueResult is a null.  I suspect this is because you 
cannot have a null value in the composite key but wanted to put it out 
there just in case.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/joDvDTCUFS4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to