0

I'm missing something here!

I'm using ISet to map collection in my NHibernate winform c# project.

Now I want to do something like this:

Person _person=new Person();

Address _address1=new Address();
_person.Addresses.Add(_address1);
_address1.Person=_person;

Address _address2=new Address();
_person.Addresses.Add(_address2);
_address2.Person=_person;

_session.Save(_person);

Now Addresses is an HashedSet<Address> and when I try to add _address2, "Add" method return false because Address Id is null and the object cannot be added... _address1 Id is null too!

How to resolve?

Daniele

danyolgiax
  • 12,798
  • 10
  • 65
  • 116

1 Answers1

2

You need to set some properties on the Address and implement object equality so that the set implementation can test equality. For example, I doubt the Address Id is a good test for equality. Rather, you would want to test the number, street, city, etc for equality.

Mark Sherretta
  • 10,160
  • 4
  • 37
  • 42