Consider this simple example.
public class Parent
{
private IList<Child> m_children = new List<Child>();
public virtual Guid ParentID{get;set;}
public virtual string Name{get;set;}
public virtual IList<Child> Children{
get{return m_children;}
set{m_children=value;}
}
}
public class Child
{
public Guid ChildID{get;set;}
public virtual string Name{get;set;}
}
I would map the relationship this way.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Parent">
<id name="ParentID">
<generator class="native" />
</id>
<property name="Name" column="FirstName" type="String"/>
<bag name="Children">
<key column="ParentId"/>
<one-to-many class="Parent"/>
</bag>
</class>
</hibernate-mapping>
Now, I can create a parent and add children, and store that to the
database. However, if I create a parent with no children and add it
to the database, when I retrieve that parent, the Children property
throws an ObjectNotFoundException - no row in table... What is the
proper way to handle an empty collection like this? How do I add
events to an existing parent?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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.