Some functions in NHibernate IList are not working, if objects are using lazy properties.

Description

In example IList.Remove(object), IList.IndexOf(object) are not working for ILists (Bags in mapping) delivered by NHibernate if objects are using lazy properties.

[Test]
public void Can_NH_IListFindIndexOfObject()
{
using (ISession session = this.OpenSession()) {
ClassB result = session.Get<ClassB>(1);
Assert.AreEqual(3, result.classA_list.Count, "NHibernate-Ilist: Not all objects loaded");

ClassA NH_objToFind = result.classA_list[1]; //lets take second one (with index 1)
int NH_indx = result.classA_list.IndexOf(NH_objToFind);

Assert.AreEqual(1, NH_indx, "NHibernate-Ilist: object not found !");
}
}

[Test]
public void Can_NH_IList_RemoveObject()
{
using (ISession session = this.OpenSession()) {
ClassB result = session.Get<ClassB>(1);
Assert.AreEqual(3, result.classA_list.Count, "NHibernate-Ilist: Not all objects loaded");

ClassA NH_objToDelete = result.classA_list[1]; //lets take second one (with index 1)
Assert.IsNotNull(NH_objToDelete, "NHibernate-Ilist: object not found !");

result.classA_list.Remove(NH_objToDelete);

Assert.AreEqual(2, result.classA_list.Count, "NHibernate-Ilist: object was not removed from list");
}
}

Please see attached Test

Environment

None

Assignee

Alex Zaytsev

Reporter

Jenar

Components

Affects versions

Priority

Major
Configure