I'm porting an app from Ayende's Generics and 1.0.3 to pure 1.2 (so removing Ayende's Generics) and am running into an issue I can't find documentation on.. (based on the few blogs that talk about this kind of porting.
I keep getting the following exception when I run my "add" routines.
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)
C:\Projects\myProject\User.cs(174,0): at MyNameSpace.UserBase.AddOwnedNode(INode node)
Below is the add routine I am using
Code:
/**** The Add Routine ****/
public void AddOwnedNode(INode node)
{
if (_ownedNodes.Contains(node)) return;
_ownedNodes.Add(node);
if (node.Owner == null)
node.Owner = this;
else if (!node.Owner.Equals(this))
node.Owner = this;
}
/**** The property & Field ****/
private IList<INode> _ownedNodes = new List<INode>();
public virtual IList<INode> OwnedNodes
{
get { return new ReadOnlyCollection<INode>(_ownedNodes); }
set { _ownedNodes = value; }
}
/**** The Mapping XML for this field ****/
<bag name="OwnedNodes" lazy ="true" inverse ="true" >
<key column="OwnerUserFk"/>
<one-to-many class ="MyNameSpace.INode, MyNameSpace.Interfaces"/>
</bag>
/**** The mapping for the other side (node.Owner) ****/
<many-to-one name="Owner" class="MyNameSpace.IUser, MyNameSpace.Interfaces" column ="OwnerUserFk" not-null="true" />
Notes: I am using Interfaces and sub-classes. The technique is based on a blog post I read but goes like this
Code:
<class name="[My Interface Name]" >
<!---- All class properties that have setters in the interface ---->
<subclass name="[My Class Implientation name]" discriminator-value="something">
<!---- My class properties that don't have setters in the interface ---->
</subclass>
</class>
BUT I'm not thinking that this is related to my issue. As the maps are compiling and working fine..
Am I being stupid (My guess is yes) and PersistentGenericBag is read-only.. or am I missing something?
Thanks in advance fo the help.
Josh