Wombat
Wombat

Reputation: 172

Saving extra information with Many To Many collection

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?

Upvotes: 0

Views: 105

Answers (1)

Ian Nelson
Ian Nelson

Reputation: 58723

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."

Upvotes: 5

Related Questions