views:

12

answers:

1

Hi all

Let's say you have two classes, Person and Address.

Person has a reference to Address like this:

public class Person
{
  public virtual Address Residence {get;set;}
}

Address has an override of .Equals which determines whether two Address instances represent the same physical address (by comparing postcode and first line, say).

Let's say you have two unsaved Person objects which hold references to two unsaved Address objects, which are separate (in terms of reference equality) but equal in terms of .Equals implementation.

Will NHibernate issue one INSERT or two?

Thanks

David

+1  A: 

It will insert twice. Having it match two transient instances by equality is not technically possible.

The calling code would be responsible for matching those instances and replacing them by the same reference.

Diego Mijelshon
Cool thank you.
David