Hi,
i have an MasterObject with an aggregated Collection. If i save the Master - why in the world are all the Objects in the Collection also validated even if they where not modified!?
Steps to Reproduce:
- Run the MainDemo and create a new Resume with one PortfolioFileData object (refer to the attached screenshot).
- Save the Resume object;
- Set breakpoints into the OnSaving method of both Resume and PortfolioFileData classes;
- Assign a Contact to the Resume object and press the Save button - see that the OnSaving method is fired only in the Resume class - this is the expected and default behavior of XPO;
- Now go to the database, fine the FileData table and clear the Size, FileName, Content properties columns of a row that corresponds to the PortfolioFileData object you added;
- Clear the Contact property of the Resume object and now press the Save button - the validation error occurs as expected because the required File property of the PortfolioFileData object is not set (we cleared it for the test purpose).
I might be wrong, but I expect that only the rules of the Resume object should be checked in this scenario. So, since the Resume class has no validation rules no validation errors should appear here.
Hello Noxe,
>>i have an MasterObject with an aggregated Collection. If i save the Master - why in the world are all the Objects in the Collection also validated even if they where not modified!?
As you know, the validation works against a validation context (for example, saving, deleting). When you save a master object the ObjectSpace.Committing event fires and triggers, checking the validation rules.
However, I debugged our MainDemo a little bit (the Resume and PortfolioFileData classes), to see whether the OnSaving method hits for the PortfolioFileData class when a Resume object is saved. In my tests, I see that it's not fired and so your frustration regarding the current behavior is fully understandable. We should perform additional research in this regard, to understand whether it's possible to workaround this behavior. Anyway, I'll treat this as a bug, and will convert your question to a bug report.
We apologize for the inconvenience it caused you and your business. We will keep you informed of our progress. Please bear with us.
Thanks,
Dennis
Hi Dennis,
thx for your Infos - i think the problem is in the PersistenceValidationController - GetObjectsToValidate method:
if(currentObject != null) {
modifiedObjects.Add(currentObject);
aggregatedObjects.AddRange(FindAggregatedObjects(currentObject));
modifiedObjects.AddRange(aggregatedObjects);
}
…