Hi,
I am having a problem with a property accessor on a POCO using generic lists. The property works fine on the POCO class directly, but not on the NHibernate generated proxy. (I'm using NHibernate 1.2.1.GA)
I used the following class definition:
Code:
public class MyPoco
{
private int _id;
private List<MyPoco> _transientRelatedItems = new List<MyPoco>();
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
public virtual IList<MyPoco> TransientRelatedItems
{
get { return _transientRelatedItems; }
}
public virtual void AddToRelatedParent(MyPoco relatedParent)
{
relatedParent._transientRelatedItems.Add(this);
Trace.Assert( relatedParent._transientRelatedItems == relatedParent.TransientRelatedItems,
"The accessor should return the same reference as the member variable");
}
}
And the following mapping file:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="GenericListProblemDemo.MyPoco, Runner"
table="MyPoco">
<id name="Id" column="Id">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
... and when I execute the following code, the Trace.Assert() call fails:
Code:
MyPoco persistentParent = session.Load<MyPoco>(1);
MyPoco transientChild = new MyPoco();
transientChild.AddToRelatedParent(persistentParent);
I've uploaded a complete example here:
http://www.uploading.com/files/RXVQE3XA/NhGenericListProblem.zip.html
(just open the 'Command Prompt.bat', and type nant)
It looks like the overriden property accessor (in the NHibernate generated proxy) is returning a different collection to the original property accessor. Note, the collection is not mapped/persisted - it's meant to contain transient references.
Has anyone seen this before? Any help would be appreciated.
Thanks,
Richard