Hi,
A quick question, which is probably very easy ??... I have 2 entities to commit to the database. 1 entity references the other with a foreign key...
I can save the first entity, then assign the foreign key to the second entity and save the second entity which is fine.
My question is, is there a way to do this in one "transaction", ie is assign automatically as I probably will have more entities to. I am doing the following but the save is not assigning the foreign key after the Save(). See code below.. I have also lloked at the "UnitOfWork" object which may or may not help me, any pointers would be great
Many thanks
Richard
Transaction t = new Transaction(IsolationLevel.ReadCommitted, "Client Save");
try {
//Add the customer for saving
work.AddForSave(customer);
t.Add(customer);
customer.Save();
//set the billing
billing.CGuid = customer.CGuid;
billing.AddType = (byte)AddressType.BillingAddress;
//set the shipping
shipping.CGuid = customer.CGuid;
shipping.AddType = (byte)AddressType.ShippingAddress;
//Add the addresses to the unit of work
t.Add(billing);
t.Add(shipping);
billing.Save();
shipping.Save();
t.Commit();
} catch (Exception e) {
t.Rollback();
LogManager.WindowsLogError("Customer add failure "+e.Message);
return false;
} finally {
t.Dispose();
}