views:

18

answers:

1

I am used to hbm files and have started using fluent nhibernate recently.

Creating an m-to-m relationship between two entities A and B is quite simple

In entity A, I create:

public virtual IList<B> Bs { get; set; }

and then I use:

mapping.HasManyToMany(x => x.Bs);

That’s it and I can do:

A a = new A();
a.Bs.Add(b);

My problem is that I would like to have an additional column in my dedicated m-to-m database table which holds the two foreign keys. What is the simplest way to achieve this in FNH?

Would I have to create a dedicated entity for the m-to-m realtionship or is there a simpler solution?

A: 

You have to map many-to-many with additional data relationships as two one-to-many relationships. So, yes, you do need to create a dedicated entity in your model for this.

Jamie Ide
ok thanks - i was afraid that this is necessary.
csetzkorn
I appreciate you accepting the question but you should allow some time for dissenting opinions. I'd be happy to learn that I'm wrong or there's a better way.
Jamie Ide
I think what you said makes sense - that's what I did in the past as well.
csetzkorn