Tôi có một cơ sở dữ liệu kế thừa và tôi đang cố gắng tạo ra một DAL NHibernate. Tôi gặp sự cố với ánh xạ trên bảng Nhiều người.NHibernate Nhiều-nhiều-nhiều
Các bảng cơ sở dữ liệu:
studio_Subscribers
studio_Groups
(chứa một IList của thuê bao)studio_Subscribers_Groups
- Nhiều-To-Nhiều bảng với khóa chính
Vấn đề là khi Tôi tạo một phiên bản SubscriberGroup
và điền vào nó với Người đăng ký họ được lưu vào bảng studio_Subscribers
nhưng không đến bảng Nhiều người.
Tôi không thể tìm ra điều gì sai?
studio_Subscribers
bảng vẽ bản đồ:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Meridix.Studio.Common"
namespace="Meridix.Studio.Common">
<class name="SubscriberItem" table="studio_Subscribers">
<id name="StorageId" column="Id" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity" />
</id>
<property name="Id" column="DomainId" not-null="true" />
<property name="Subscriber" column="Subscriber" not-null="true" length="50" />
<property name="Description" column="Description" not-null="false" length="100" />
<property name="Type" column="Type" not-null="true" length="40"
type="Meridix.Studio.Data.Repositories.EnumStringTypes.SubscriberTypeEst, Meridix.Studio.Data.Repositories" />
</class>
</hibernate-mapping>
studio_Groups
mapping bảng:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Meridix.Studio.Common"
namespace="Meridix.Studio.Common">
<class name="SubscriberGroup" table="studio_Groups">
<id name="StorageId" column="Id" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity" />
</id>
<property name="Id" column="DomainId" not-null="true" />
<property name="Name" column="Name" not-null="true" length="200" />
<property name="Description" column="Description" not-null="false" length="300" />
<bag name="Subscribers" table="studio_Groups_Subscribers" access="nosetter.camelcase">
<key column="GroupId"></key>
<many-to-many column="SubscriberId" class="SubscriberItem" />
</bag>
</class>
</hibernate-mapping>
jishi: Bạn đã lưu tôi. cảm ơn. Để phần còn lại: Hãy chắc chắn rằng bạn có cả hai lớp tham chiếu lẫn nhau, xác định hai túi trên mỗi bên (đảm bảo rằng một trong hai túi là nghịch đảo, một là không). Và đừng quên đặt tham chiếu trong runtinme: a.bList.Add (b); b.aList.Add (a); – Nils