user725388
user725388

Reputation:

Two table mapping in single map class

I have a table structure something like this

table Collection
  Id
  Name

table Product
  Id
  Name

table Item
  Id
  Collection_Id
  Product_Id

What i would like is to map the Collection above to one single class named:

Class Collection
  Id
  Name
  List<Product> Products

and I have Product class is :

Class Product
  Id
  Name

How do I do that with fluent nhibernate ? Anyone have any idea ?

Upvotes: 1

Views: 117

Answers (1)

Cu Jimmy
Cu Jimmy

Reputation: 336

What you need is a many to many mapping.

You will need to have a List<> on both classes of the other object and the following mappings in your fluent file

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

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

There is a good article about what you are trying to do here

Upvotes: 1

Related Questions