2010/5/21 BZaino <[email protected]>:
> Hi,
> I have a parent child relationship between a Person object and and
> Address object.  The Person object exists in the DB.  After doing a
> Get on the Person, I add a new Address object to the Address sub-
> object list of the parent, and do some other updates to the Person
> object.  Finally, I do an Update on the Person object.  With a SQL
> trace window, I can see the update to the Person object to the Person
> table and the Insert of the Address record to the Address table.  The
> issue is that, after the update is performed, the AddressId (primary
> key on the Address object) is still set to  0, which is what it
> defaults to when you first initialize the Address object.  I have
> verified that when I do an Add, this value is set correctly.  Is this
> a known issue when trying to add sub-objects as part of an NHibernate
> UPDATE?  Sample code is below
>
> Thanks
>
>            Person newPerson = new Person();
>            newPerson.PersonName = "John Doe";
>            newPerson.SSN = "111111111";
>            newPerson.CreatedBy = "RJC";
>            newPerson.CreatedDate = DateTime.Today;
>            personDao.AddPerson(newPerson);
>
>            Person updatePerson =
> personDao.GetPerson(newPerson.PersonId);
>
>            updatePerson.PersonAddresses = new List<PersonAddress>();

Should probably be handled inside Person class.


>            PersonAddress addr = new PersonAddress();
>            addr.AddressLine1 = "1 Main St";
>            addr.City = "Boston";
>            addr.State = "MA";
>            addr.Zip = "12345";
>            updatePerson.PersonAddresses.Add(addr);
>
>            personDao.UpdatePerson(updatePerson);

Why? Is the dao closing the ISession and returning detached entities?


>            int addressID = updatePerson.PersonAddresses[0].AddressId;
>


Mappings for Person and PersonAddress?


/Oskar

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to