I'm using 1.2.0 CR1 and I am getting the oddest error when I try to do an Add to any of my bags.
Code:
System.NotSupportedException : Collection is read-only.
at System.ThrowHelper.ThrowNotSupportedException(ExceptionResource resource)
at System.Collections.ObjectModel.ReadOnlyCollection`1.System.Collections.Generic.ICollection<T>.Add(T value)
at NHibernate.Collection.Generic.PersistentGenericBag`1.Add(T item)
Here is what my bag Maps look like
Code:
<bag name="LoginHistory" inverse="true" access="nosetter.camelcase-underscore" cascade="delete">
<key column="UserFk"/>
<one-to-many class ="UserLoginHistory"/>
</bag >
here is what the actual property looks like..
Code:
private IList<UserLoginHistory> _loginHistory = new List<UserLoginHistory>();
public IList<UserLoginHistory> LoginHistory
{
get { return new ReadOnlyCollection<UserLoginHistory>(_loginHistory); }
}
and here is what my add function looks like (all wrapped up so that child gets to know its parent :-)..)
Code:
public void AddLoginHistory(UserLoginHistory history)
{
if (_loginHistory.Contains(history)) return;
_loginHistory.Add(history); // < -- this is where the fails (and notice.. its the private IList not the public read only IList)
if (history.User==null)
history.User = this;
else if (!history.User.Equals(this))
history.User = this;
}
Now I am fairly firmilar with 1.0.X NHibernate and have been using it for a while.. so I am trying to move forward to 1.2 and use generics but this just stumps me? Is it because inverse="true"? if so I am ok with that.. I just need to know how to force a refresh of my collections to reflect freshly added children.
Thanks in advance for the help :-)
Josh