views:

118

answers:

2

I have 3 DB Tables: Person, Address, and PersonAddress. Person Address is a simple join table (only stores the IDs of Person and Address).

In my domain model, I have Person and Address. Person is configured to have a many-to-many relationship to Address (through PersonAddress). In code, this is implemented with List<Address>.

I've been told that I will get better performance from nHibernate if I...

  1. Create a PersonAddress domain object
  2. Configure Person to have a one-to-many relationship to PersonAddress
  3. Configure a a many-to-many index for Address on this relationship
  4. Implement it in code with a Dictionary<Address, PersonAddress>

Is this true?

+2  A: 

I wouldn't create an unnecessary class in the domain just because of that. The use of a dictionary for better performance also sounds weird to me.

You could use an idbag, this is faster to update. (This is mapped as a List in the domain, but has an id in the database).

There are always different things to consider about performance. There is a very interesting chapter in the reference documentation about collection performance.

Stefan Steinegger
+1  A: 

I also would not introduce a complex mapping for the sakes of performance in NHibernate until the need for doing so is established.

Along with the standard many-to-many mapping you can use the a one-to-many strategy with the PersonAddress object (PersonAddress has a collection of Persons and a collection of Addresses). This strategy is used when you want to maintain additional information about the Person-Address relationship.

Michael Gattuso