Just for an example, lets say you made a screen that simply let someone key in an additional line item to an invoice. Further, assume you loaded the InvoiceEntity so you could display basic invoice information (you did not load or display the other line items).
They hit save you write code:
myOrderEntity.LastUpdated=DateTime.Now;
myOrderEntity.Updatedby="Some User";
LineItemEntity myLineItem = new LineItemEntity();
myLineItem.Descrption="Whatever they entered";
myLineItem.Quantity=12;
myLineItem.Price=15.53;
myOrderEntity.LineItem.Add(myLineItem);
myOrderEntity.Save(true);
Note, this code above does exactly what you I want and works exactly as one would expect it to, with the exception of having a side effect of loading all the LineItemEntities into memory when they are not needed.
Granted there are other ways to accomplish this - however the above is the most intuitive and simple - so I just want to stop lazy loading. There already is a switch to force lazy loading to fetch EVERY time - this is the opposite of that switch.
Here is how I had to rewrite the above code:
Transaction transactionManager = new Transaction(IsolationLevel.ReadCommitted, "someTrans");
try
{
myOrderEntity.LastUpdated=DateTime.Now;
myOrderEntity.Updatedby="Some User";
transactionManager.Add(myOrderEntity);
myOrderEntity.Save();
LineItemEntity myLineItem = new LineItemEntity();
myLineItem.Descrption="Whatever they entered";
myLineItem.Quantity=12;
myLineItem.Price=15.53;
myLineItem.OrderEntityId=myOrderEntity.OrderEntityId;
transactionManager.Add(myLineItem);
myLineItem.Save();
transactionManager.Commit();
}
catch
{
transactionManager.Rollback();
throw;
}
finally
{
transactionManager.Dispose();
}
I dont think there is any question about which code is best to read!