Blimey! Forgot all about this issue until it just bit me again.
The LLBLGen project file should be available in the private area in another query. If not, move this there and I'll post it up.
The problem is this line which is part of the save routine for a FeeInvoice:-
feeInvoice.NominalTransaction = feeInvoice.CreatePosting();
CreatePosting() will always return a new NominalTransactionEntity or null.
In this scenario, just before the above line is called:-
feeInvoice.NominalTransaction is null (because it isn't part of the prefetch).
feeInvoice.NominalTransactionID (int?) is set to 2698.
The above line does not set feeInvoice.NominalTransactionID to null, it stays at 2698.
LLBLGen therefore sees no change and no change is made to NominalTransactionID in the database.
So when I subsequently delete NominalTransaction with ID=2698, it blows up with a Foreign Key exception.
So the problem seems to be that when a related entity property is not prefetched, it cannot be set to null to remove any existing related entity.
Is this the expected behaviour?