保存多对多相关实体时,实体保存正常。但是联结表保持空白:
产品侧的映射(ProductMap.cs)
HasManyToMany(x => x.Pictures)
.Table("Product_Picture")
.ParentKeyColumn("Product")
.ChildKeyColumn("Picture")
.Cascade.All()
.Inverse()
这会生成以下xml:
<bag cascade="all" name="Pictures" table="Product_Picture">
<key>
<column name="Product" />
</key>
<many-to-many class="...Picture...">
<column name="Picture" />
</many-to-many>
</bag>
图片侧的映射(PictureMap.cs)
HasManyToMany(x => x.Products)
.Table("Product_Picture")
.ParentKeyColumn("Picture")
.ChildKeyColumn("Product")
.Cascade.All();
这会生成以下xml:
<bag inverse="true" cascade="all" name="Products" table="Product_Picture">
<key>
<column name="Picture" />
</key>
<many-to-many class="...Product...">
<column name="Product" />
</many-to-many>
</bag>
有什么想法吗?
答案 0 :(得分:0)
您必须确保在Picture
对象上添加集合,这是您未声明为Inverse()
的关系的方向。添加到关系的另一端不会导致它们被持久化。
如果你这样做,或者正在添加到双方,那么请发布你正在操作的一些代码并尝试保存这些对象。