0

I am trying to build a mapping for the following problem. A Case can have multiple clients and a client can be attached to multiple Cases.

i have these mappings : Case

 Map(x => x.CaseNumber);
        References(x => x.Status).Cascade.All();
        HasManyToMany<Client>(x => x.Clients)
        .Table("CaseToClient")
        .Access.CamelCaseField(Prefix.Underscore)
        .Cascade.SaveUpdate()
        .LazyLoad();

Now my CaseToClient Table consists of Case_Id and Client_Id what i want is another column in the table with in it a boolen of the client is relevant for the case. How can i add the column so that i can write the property?

Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
Wombat
  • 172
  • 3
  • 10
  • 2
    this question was asked earlier this year: http://stackoverflow.com/questions/2281648/how-to-add-extra-field-in-the-manytomany-generated-table-with-fluentnhibernate – Marijn Nov 26 '10 at 15:34
  • and well before that too: http://stackoverflow.com/questions/889513/nhibernate-many-to-many-mapping-additional-column-in-the-mapping-table http://stackoverflow.com/questions/166426/additional-fields-in-nhibernate-many-to-many-relation-tables http://stackoverflow.com/questions/472052/many-to-many-mapping-with-extra-columns-in-join-table – Mauricio Scheffer Nov 26 '10 at 17:52

1 Answers1

5

Don't use many to many, use two one-to-many mappings.

Create a separate entity for ClientCase, which references both Case and Client and also has your boolean property.

From NHibernate In Action, page 193:

"we avoid the use of many-to-many associations because there is almost always other information that must be attached to the links between associated instances; the best way to represent this information is via an intermediate association class."

Ian Nelson
  • 57,123
  • 20
  • 76
  • 103