I need to an email address like so:
Code:
EmailAddresse newEmailAddress = new EmailAddresse();
newEmailAddress.emailaddress = "Test@test.com";
newEmailAddress.whenchanged = System.DateTime.Now;
newEmailAddress.whencreated = System.DateTime.Now;
int newlySavedEmailAddress = (int)session.Save(newEmailAddress);
The last line returns the id of the email that was just added to the db.
I then add a contact and pass in this new id to a field in the contact table like so:
Code:
Contact newContact = new Contact();
newContact.title = "Mr";
newContact.name = "George";
newContact.surname = "Robinson";
newContact.primaryemailaddress = newlySavedEmailAddress;
newContact.birthdate = DateTime.Now;
newContact.whenchanged = DateTime.Now;
newContact.whencreated = DateTime.Now;
int newlySavedContact = (int)session.Save(newContact);
What I want to do is take the id of the newly added field in the contact table and pass it back into another field in the email table (one above).
Problem is i had to do this
Code:
int newlySavedEmailAddress = (int)session.Save(newEmailAddress);
to get the id, now i know that this hasn't been saved to the db yet (this is a tranasaction). But how do I add the id of the contact into a foreign key of the email when I ive already saved the email to session? Is it possible.
Help..................