Problem with mapping a many-to-many relation (mapping by code)?

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I'm using a new to NHibernate 3. 2 mapping by code (not fluent nhibernate) and I have a little problem with mapping a many-to-many relation. I want to map these entities public class Article { public virtual Guid Id { set; get; } public virtual string Content { set; get; } public virtual string Title { set; get; } public virtual IList Tags { set; get; } } public class Tag { public virtual Guid Id { set; get; } public virtual string Name { set; get; } public virtual IList Articles { set; get; } } public class ArticleTag { public virtual Article Article { set; get; } public virtual Tag Tag { set; get; } } My mapping looks that public class TagMapping : ClassMapping { public TagMapping() { Id(x => x.

Id); Property(x => x. Name); Bag(x => x. Articles, x => x.

Inverse(true), x => x. ManyToMany(z => { z. Column("Article"); z.

Lazy(LazyRelation. Proxy); })); } } public class ArticleTagMapping : ClassMapping { public ArticleTagMapping() { ManyToOne(x => x. Article, x => { }); ManyToOne(x => x.

Tag, x => { }); } } public class ArticleMapping : ClassMapping { public ArticleMapping() { Id(x => x. Id, x => x. Generator(Generators.

Guid)); Property(x => x. Content, x => x. Length(4002)); Property(x => x.

Title); Bag(x => x. Tags, x =>{ }, x => x. ManyToMany(z => { z.

Column("Tag"); z. Lazy(LazyRelation. Proxy); })); } } The only problem is that, when I generate tables in database using this schema, I have two additional tables.

What I must change to disable generating these two tables (Articles and Tags)? Nhibernate nhibernate-mapping link|improve this question asked Jul 10 '11 at 23:37lszk45828 81% accept rate.

Public class ArticleTagMapping : ClassMapping { public ArticleTagMapping() { ManyToOne(x => x. Article, x => { }); ManyToOne(x => x. Tag, x => { }); } }.

I already figured it out, if I remove this mapping, the database tables diagram will look like I want to. But I don't want to have a relation in code 1:1. I want in code have the same situation, that means n:m relation divided to three entities.

I don't want a situation, that I have e.g. Customer:company relation and now I need to add a DateTime object to check when customer was associated with company. I have problem, how to appropriate mapping this relation. – lszk Jul 11 '11 at 17:07 For what I can see, that is not a N:M (well it is DB level), but I guess what you are seeing at the end are two relationships of 1:N type.

Customer (1) - (N) company_customer (N) - (1) company. What you think? – Rui Lima Jul 11 '11 at 17:55 "...run into a situation where you have what appears to be a many-to-many relationship, but the “join table” has extra, non-ID data columns in it.

This is not a real many-to-many relationship. It is, in fact, a ternary relationship. Another way of looking at it is two OTM/MTO relationships between the two main tables and the intermediate table (i.e.

, the “join table” with extra information). You can think of it logically as a many-to-many relationship, but you should model it as a ternary relationship. " taken from code-magazine.com/… – Rui Lima Jul 11 '11 at 23:32.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions