Joachim Kerschbaumer
Joachim Kerschbaumer

Reputation: 9881

additional fields in NHibernate many-to-many relation tables

when i have a many-to.many relation with nhibernate and let nhibernate generate my db schema, it adds an aditional table that contains the primary keys of the related entities. is it possible to add additional fields to this and access them without having to hassle around with sql manually?

Upvotes: 3

Views: 2263

Answers (3)

Alexandre
Alexandre

Reputation:

In this case, how would you build the in the mapping file for the new entity (that acts as the bridge between the two initial tables) ? In my case this link table has two foreign keys (int), one for each initial table, plus some other fields (startDate, endDate)

The thing is, in my new entity, I do not have properties for these two foreign keys. I only have one property that is of the type of the entity the foreign key is pointing to.

Upvotes: 0

Santiago Palladino
Santiago Palladino

Reputation: 3542

Agree with Jasper. What you are modeling in that case is not a relation but an entity itself, with 1-N and N-1 relations to the other two entities.

It is not that NHibernate cannot handle it, it is that you simply cannot model it.

Upvotes: 0

Jasper
Jasper

Reputation: 846

I don't think thats possible. If you are saying that the relation has some state than in essence it is an object in it's own right and should be treated (mapped) as such.

Upvotes: 6

Related Questions