Je commence juste à travailler avec NHibernate. J'ai installé d'un simple nombre à plusieurs scénarios en utilisant les produits et fournisseurs comme suit:NHibernate Propriétés d'objet de domaine many-to-many
<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>
Je suis maintenant essayer de câbler les sacs à mes objets de domaine. La lecture de la documentation que je suis venu avec (à l'aide 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
Cependant, quand je tente d'ajouter un fournisseur à un produit et STOCKER je reçois l'erreur suivante
Impossible de jeter objet de type 'NHibernate.Collection.PersistentBag' de type 'Iesi.Collections.HashedSet
J'ai essayé d'utiliser toutes sortes de types, par exemple, ICollection et List (Of T) mais je continue d'obtenir l'erreur équivalente.
Impossible de jeter l'objet de type « NHibernate.Collection.Generic.PersistentGenericBag 1[Domain.Supplier]' to type 'System.Collections.Generic.List
1 [Domain.Supplier]
Qu'est-ce que je manque ici?
Merci beaucoup fonctionne parfaitement! –