I have a gridview that is bound to the result from an nhibernate query. If the first item in the list is edited the following exception is thrown:
System.Refle
Very late, but should help others with the same problem. The solution I used is to wrap a custom list (in this case a NotificationList) around the field in the getter.
private IList _parameters = new List();
get
{
return new NotificationList(_parameters);
}
This list is a wrapper around the list, so that databinding will be forwarded to the original list.
public class NotificationList : IList, IList
{
IList myList;
public NotificationList(IList list)
{
myList = list;
}
int IList.Add(object item)
{
myList.Add ((T) item);
}
// implement both IList and IList
// ...
}
For me this fixed the issue with the databinding, but created a side effect where every time the session was flushed all the items in the collection get updated in the DB, wether they changed or not. To resolve that, I changed the mapping to access the field directly. See this on Hibernate, which applies to NHibernate as well.
This is the new (Fluent) mapping:
HasMany(x => x.Parameters)
.Cascade.All()
.Access.CamelCaseField(Prefix.Underscore);