Best place to add a history record to the graph of an entity

Posts   
 
    
Posts: 77
Joined: 05-May-2005
# Posted on: 11-Feb-2013 15:36:08   

I am using LLBLGen v3.1 with an adapter project targeting the 4.0 framework and a SQL Server Express database.

I have a PassEntity and under certain circumstances I want to create a PassHistoryEntity when the PassEntity is saved. So I coded this:

PassEntity pass = new PassEntity(); <set some fields> adapter.SaveEntity(pass, true, true); // refetch, recurse

and in the PassEntity I have coded this:

protected override void OnBeforeEntitySave() { // insert a history record? PassHistoryEventType eventType = GetEventType(); if (eventType != PassHistoryEventType.NoEvent) { PassHistoryEntity history = new PassHistoryEntity(); history.TransitAccountId = this.TransitAccountId; history.TaXFpId = this.TaXFpId; history.ApiLogId = this.ApiLogId; history.EventType = (int)eventType; history.ExpirationDtm = (DateTime)this.ExpirationDtm; history.StartDtm = this.StartDtm; history.EndDtm = this.EndDtm; this.PassHistories.Add(history); }

base.OnBeforeEntitySave();

}

I have set breakpoints in the OnBeforeEntitySave method, and I know that it is creating the PassHistory entity and adding it to the PassHistories collection in the PassEntity. I even checked that the PassHistoryEntity IsNew and IsDirty. But the PassHistoryEntity is not persisted to the database even though I have coded a recursive save of the PassEntity. Is there another method I should be overriding instead?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 11-Feb-2013 19:21:34   

This was discussed here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8412 I recommend using the Auditing approach.

Posts: 77
Joined: 05-May-2005
# Posted on: 12-Feb-2013 16:48:30   

Good suggestion. Thanks.