many-to-many performance concerns with fluent nhibernate.

Posted by Ciel on Stack Overflow See other posts from Stack Overflow or by Ciel
Published on 2011-03-20T15:51:47Z Indexed on 2011/03/20 16:10 UTC
Read the original article Hit count: 292

I have a situation where I have several many-to-many associations. In the upwards of 12 to 15. Reading around I've seen that it's generally believed that many-to-many associations are not 'typical', yet they are the only way I have been able to create the associations appropriate for my case, so I'm not sure how to optimize any further.

Here is my basic scenario.

class Page {
  IList<Tag> Tags { get; set; }
  IList<Modification> Modifications { get; set; }
  IList<Aspect> Aspects { get; set; }
}

This is one of my 'core' classes, and coincidentally one of my core tables. Virtually half of the objects in my code can have an IList<Page>, and some of them have IList<T> where T has its own IList<Page>.

As you can see, from an object oriented standpoint, this is not really a problem. But from a database standpoint this begins to introduce a lot of junction tables.

So far it has worked fine for me, but I am wondering if anyone has any ideas on how I could improve on this structure. I've spent a long time thinking and in order to achieve the appropriate level of association required, I cannot think of any way to improve it. The only thing I have come up with is to make intermediate classes for each object that has an IList<Page>, but that doesn't really do anything that the HasManyToMany does not already do except introduce another class. It does not extend the functionality and, from what I can tell, it does not improve performance.

Any thoughts? I am also concerned about Primary Key limits in this scenario. Most everything needs to be able to have these properties, but the Pages cannot be unique to each object, because they are going to be frequently shared and joined between multiple objects.

All relationships are one-sided. (That is, a Page has no knowledge of what owns it). Because of this, I also have no Inverse() mapped HasManyToMany collections.

Also, I have read the similar question : Usage of ORMs like NHibernate when there are many associations - performance concerns

But it really did not answer my concerns.

© Stack Overflow or respective owner

Related posts about Performance

Related posts about nhibernate