title: Another NHibernate Mapping Mystery! Getting count in hbm file
body: <p>I am trying to retrieve the count of items allocated to a container in my hbm file. I've done a bit of digging and managed to get my hbm code this far (below!). I want the count to be retrieved every time a container object is queried. I could use an interceptor but I assume there's a better way. Am I on the right track or should I use a different strategy to get the count loaded up? </p>
  
  <p>Thanks.</p>
  
  <p>P.S. We're using NH v2.2</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" assembly="MyEntities" namespace="Entities.Containers"&gt;   &lt;class name="Container" table="[Container]" xmlns="urn:nhibernate-mapping-2.2"&gt;
      &lt;id name="Id" column="Id" type="Int32" unsaved-value="0"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;property name="Capacity" column="Capacity"&gt;
        &lt;column name="Capacity" /&gt;
      &lt;/property&gt;
      &lt;property name="Description" column="Description" length="50" type="String"&gt;
        &lt;column name="Description" /&gt;
      &lt;/property&gt;
      &lt;loader query-ref="sqCurrentContainerAllocation"/&gt;   &lt;/class&gt;
  
    &lt;sql-query name="sqCurrentContainerAllocation"&gt;
      &lt;return-scalar column="AllocatedItemsCount" type="int"&gt;&lt;/return-scalar&gt;
        SELECT COUNT(*) FROM [ContainerTracking]
        WHERE [ContainerId] = :Id   &lt;/sql-query&gt; 
     &lt;/hibernate-mapping&gt;
  </code></pre>