Nhibernate 单映射类中的双表映射

Nhibernate 单映射类中的双表映射,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,Fluent Nhibernate Mapping,我有一个这样的桌子结构 table Collection Id Name table Product Id Name table Item Id Collection_Id Product_Id 我希望将上述集合映射到一个名为: Class Collection Id Name List<Product> Products 我如何用流利的nhibernate做到这一点?有人知道吗?您需要的是多对多映射 您需要在fluent文件中列出另一

我有一个这样的桌子结构

table Collection
  Id
  Name

table Product
  Id
  Name

table Item
  Id
  Collection_Id
  Product_Id
我希望将上述集合映射到一个名为:

Class Collection
  Id
  Name
  List<Product> Products

我如何用流利的nhibernate做到这一点?有人知道吗?

您需要的是多对多映射

您需要在fluent文件中列出另一个对象的两个类和以下映射

    HasManyToMany(x => x.Products)
        .Table("tblCollection_Product")
        .Inverse()
        .Cascade.All();

    HasManyToMany(x => x.Collections)
        .Table("tblCollection_Product")
        .Cascade.All();

有一篇很好的文章介绍了您要做的事情

您需要的是多对多映射

您需要在fluent文件中列出另一个对象的两个类和以下映射

    HasManyToMany(x => x.Products)
        .Table("tblCollection_Product")
        .Inverse()
        .Cascade.All();

    HasManyToMany(x => x.Collections)
        .Table("tblCollection_Product")
        .Cascade.All();
有一篇关于你正在尝试做什么的好文章