Child entity `Save` overwrite not called if saved via `parent.Save(recurse: true)`

Posts   
 
    
MMStan
User
Posts: 9
Joined: 10-Aug-2016
# Posted on: 29-Sep-2025 15:33:20   

Hi, I have LLBLGen v5.9 Self-servicing model with Parent:Child table (1:N) and I have a code like this:

public partial class ChildEntity : ChildEntityBase
{
    public override bool Save(IPredicate updateRestriction, bool recurse)
    {
        Logging.Log($"SAVE");
        
        return base.Save(updateRestriction, recurse);
    }
}

I test it with this code:

// The Save overwrite is called if I call Save directly
new ChildEntity(){ bla }.Save();

// The Save overwrite is not called if it is called indirectly
var parent = new ParentEntity(123);
parent.Child.Add(new ChildEntity(){ bla });
parent.Save(recurse: true);

Is that an intention? Why is it not called if I add the entity into the parent?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39971
Joined: 17-Aug-2003
# Posted on: 30-Sep-2025 08:17:53   

Because the runtime traverses the graph by other means than calling 'Save' on the entities in the graph; it builds a set of queries to run based on the entities in the graph. The 'Save' method you call is the start of the process. The runtime will call other methods when persisting entities, however, like OnSave: https://www.llblgen.com/Documentation/5.12/ReferenceManuals/LLBLGenProRTF/html/3E981200.htm

Frans Bouma | Lead developer LLBLGen Pro