views:

832

answers:

3

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?

+4  A: 

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.

Jasper
A: 

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.

Santiago Palladino
A: 

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.

Sorry for adding my question as an answer, but I found out my own answer to my question: use a collection of dependant objects, see nhibernate doc section 7.2 for an example.