MattAdamson wrote:
Hi Frans,
Sorry I actually changed the entities slightly to address and person originally as I thought it would be easier for everyone to understand a concept more familiar.
We specifically specified in the guidelines of this forum to use the REAL names.
I actually have say a FileEntity which contains details about a file such as NoLines which I wait to actually retrieve from the local file at save time i.e. in this save override method, change the value of NoLines property from the value taken from business logic which opens the file and finds the no of lines. The actual NoLines property is in a sub property of FileEntity called FileMetricsEntity.
I wanted to add code in this override like
if(entity.IsNew)
{
// Calculate file metrics and set properties
}
Hope this makes sense now.
The problem is: when you save FileEntity, and you start creating fileMetricsEntities based on the FileEntity values, it has to be done before the queue is calculated, otherwise the entities aren't persisted obviously. So InsertEntity is way too late.
Save is also not the right candidate as it's not called when you save a collection of these entities.
So, whatever you try to do, you can't do it when the save process has been started. The problem is that you want to calculate the metrics values when the save process is started, but that entity might not exist at that point yet. It also might be that the metrics entity isn't saved as it might not be dirty and the fileentity might be not new.
If you add a new metrics entity to a new file entity (and why not, it should belong to that entity), it will always be saved when that new file entity is saved.