Here is how you can solve this by using CompositeUserType
Create a new Custom User Type by implementing the ICompositeUserType interface and implement all the relevant methods. Specify your mapping as
Code:
<property name="PhoneNumbers" type="DAL.PhoneType, DAL">
<column name="Phone1"/>
<column name="Phone2"/>
<column name="Phone3"/>
</property>
In the NullSafeGet method return an ArrayList of your PhoneNumber class:
Code:
public Object NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
{
String first = (String) NHibernateUtil.String.NullSafeGet(rs, names[0], session, owner);
String second = (String) NHibernateUtil.String.NullSafeGet(rs, names[1], session, owner);
String third = (String) NHibernateUtil.String.NullSafeGet(rs, names[2], session, owner);
ArrayList lst = null;
if (first!=null && second!=null && third!=null)
{
lst = new ArrayList(3);
lst.Add(new PhoneNumber(first));
lst.Add(new PhoneNumber(second));
lst.Add(new PhoneNumber(third));
}
return lst;
}
Your Contact class would look like this:
Code:
public class Contact
{
private string _AccountNo;
private IList _PhoneNumbers;
public virtual string id
{
set{ _AccountNo = value; }
get{ return _AccountNo; }
}
public virtual IList PhoneNumbers
{
set{ _PhoneNumbers = value; }
get{ return _PhoneNumbers; }
}
public Contact()
{
//
// TODO: Add constructor logic here
//
}
}
Hope this helps.......