mdissel wrote:
But where should i place this code?
This is my code to create and store the historyrecord (inside the BaseEntityClass)
protected override bool UpdateEntity(IPredicate updateRestriction)
{
RecordHistoryUtils.StoreRecordHistory(Expo.DAL.HelperClasses.RecordAction.Modify, this );
BedrijfContactpersoonDAO dao = DAOFactory.CreateBedrijfContactpersoonDAO();
return dao.UpdateBedrijfContactpersoon(base.Fields, base.Transaction, updateRestriction);
}
.StoreRecordHistory will create a new RecordHistoryEntity object that will hold the old values. the newly RecordHistoryEntity is also saved in this function.
Where should i place base.Transaction.Add(newRecordHistoryEntity)? and where should i commit the (new or existing) transaction without modifying anything else.
As you pass the entity to StoreRecordHistory, you have to add teh entity there to the transaction, so you can in there do: (assumes there is always a transaction).
// inside StoreRecordHistory, savedEntity is the entity passed to it
savedEntity.Transaction.Add(newRecordHistory);
// proceed as you currently do.
note: there is one caveat: when you call an entity's save method like this: Save(), there is no transaction. It is not wise to start one that late in the save process either. If you want both to be ran in the same transaction, either start one before calling save, or pass 'true' for recurse to the Save() method. This will do a recursive save but will start a transaction before doing anything else, making sure that there is a transaction available.
With an include template you can 'hide' Save() from the base classes with a new implementation which always calls Save(null, true), making sure no-one makes a mistake.