开发者

NHibernate - does NHibernate recognise object equality and change is save behaviour accordingly?

开发者 https://www.devze.com 2023-01-08 03:41 出处:网络
Let\'s say you have two classes, Person and Address. Person has a reference to Address like this: public class Person

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开发者_高级运维


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消