Im just starting to work with NHibernate. I've setup a simple many-to-many scenario using Products and Suppliers as follows:
<class name="Product" table="Products">
<id name="Id">
<generator class="guid" />
</id>
<property name="Name" />
<bag name="SuppliedBy" table="ProductSuppliers" lazy="true">
<key column="ProductId" foreign-key="FK_ProductSuppliers_ProductId" />
<many-to-many column="SupplierId" class="Supplier" />
</bag>
</class>
<class name="Supplier" table="Suppliers">
<id name="Id">
<generator class="guid" />
</id>
<property name="Name" />
<bag name="Products" table="ProductSuppliers" lazy="true" inverse="true">
<key column="SupplierId" foreign-key="FK_ProductSuppliers_SupplierId" />
<many-to-many column="ProductId" class="Product" />
</bag>
</class>
I'm now trying to wire the bags up to my domain objects. From reading the documentation I came up with (Using Iesi.Collections lib):
'In Product
Private _Suppliers As ISet = New HashedSet()
Public Overridable Property SuppliedBy() As HashedSet
Get
Return _Suppliers
End Get
Set(ByVal value As HashedSet)
_Suppliers = value
End Set
End Property
'In Supplier
Private _Products As ISet = New HashedSet()
Public Overridable Property Products() As HashedSet
Get
Return _Products
End Get
Set(ByVal value As HashedSet)
_Products = value
End Set
End Property
However, when I try and add a supplier to a product and call save I get the following error
Unable to cast object of type 'NHibernate.Collection.PersistentBag' to type 'Iesi.Collections.HashedSet
I've tried using all kinds of types, for example, ICollection and List(Of T) but I keep getting the equivalent error.
Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag1[Domain.Supplier]' to type 'System.Collections.Generic.List
1[Domain.Supplier]
What am I missing here?