Hi
For navigating my associations with NHibernate 1.0.2, I thought I'd start of easy with a simple test of the CreateFilter operation. But before I knew it I ran into a "the collection was unreferenced" exception and I don't know what I'm doing wrong!
Could you please help?! The code is below and the problem occurs in the Country.GetName() operation.
Thanks,
Pascal
Country.cs:
Code:
using System;
using System.Collections;
using Iesi.Collections;
using NHibernate;
using NHibernate.Expression;
using System.Collections.Generic;
using System.Text;
namespace Hcp.Domain.CountryModule
{
    public class Country : IEntity
    {
        private int id;
        private string code;
        private ISet countryNames;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        public ISet CountryNames
        {
            get { return this.countryNames; }
            set { this.countryNames = value; }
        }
        public string GetName(string languageCode)
        {
            using (Repository repository = new Repository())
            {
                repository.Open();
                IQuery q = repository.Session.CreateFilter(CountryNames, "where this.Id = 6");
                
                if (q.List().Count > 0){
                    return ((CountryName)q.List()[0]).Name;
                }
                else
                {
                    return "Unknown";
                }
            }
        }
    }
}
CountryName.csCode:
using System;
using System.Collections.Generic;
using System.Text;
namespace Hcp.Domain.CountryModule
{
    public class CountryName: IEntity
    {
        private int id;
        private string name;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
}
Country.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Hcp.Domain.CountryModule.Country, Hcp.Domain" table="Country">
    <id name="Id" column="id" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="Code" />
    <set name="CountryNames" inverse="false" lazy="false" cascade="all">
      <key column="countryId"/>
      <one-to-many class="Hcp.Domain.CountryModule.CountryName, Hcp.Domain"/>
    </set>
   
  </class>
</hibernate-mapping>
CountryName.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Hcp.Domain.CountryModule.CountryName, Hcp.Domain" table="CountryName">
    <id name="Id" column="id" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="Name" />
  </class>
</hibernate-mapping>