Reputation: 21
I have a two tables set up as Parent/Child e.g Customer and Address (holding either one record which is both billing and shipping record or 2 records - one billing and one shipping record). Saving a new parent child is not an issue. The issue comes when the user needs to update his details. He has two addresses that he specified when he registered. On the edit screen now, he says his billing address is same as shipping address. How do I delete the second address as well as update his details in other address and his customer details.
Thanks for your help.
Upvotes: 2
Views: 216
Reputation: 8526
You do this in a transaction.
begin transaction
delete second address.
update first address
update other details.
end transaction
The example you might be interested in on that page is:
// foo is an instance loaded by a previous Session
foo.Property = "bar";
session = factory.OpenSession();
transaction = session.BeginTransaction();
session.SaveOrUpdate(foo);
session.Flush();
transaction.Commit();
session.Close();
Upvotes: 1