In my application, I have a Project object that contains a collection of Department objects. I don’t encounter any problems saving any additions or modifications to a Department object as long as I don’t add/modify a Department’s children.
Each Department object contains a collection of Drawing objects. If I add a new Drawing object, it shows up in the Drawings collection for the Department in which the Drawing object is being added; however, the new Drawing object doesn’t get persisted to the database in this case because the IsDirty property for the Department isn’t recognized as being true.
I’ve tried instantiating a new Drawing object two ways, but it doesn’t have any effect. In the first case, I instantiated it with the following code:
Library.Drawing aDwg = aProj.Department[1].Drawings.AddNew();
In the second case, I instantiated it by first instantiating a Department object and then performing an AddNew as follows:
Library.Department aDept = aProj.Department[1];
Library.Drawing aDwg = aDept.Drawings.AddNew();
In both cases, I instantiate the proj object as follows:
Library.Project aProj = Library.Project.GetProject{ Guid for the project };
After adding the data for the new Drawing object, I attempt to save the whole thing by calling aProj.Save(), but it won’t save the changes since, as I mentioned, the aProj and aDept objects aren't recognized as being dirty.
My question is why doesn’t the application recognize the Department object as being dirty when a child object is added to a collection contained within the Department object?
I overrode it in the Project object thusly:
public override bool IsDirty
{
get { return base.IsDirty || _department.IsDirty; }
}
and overrode it in the Department object thusly:
public override bool IsDirty
{
get { return base.IsDirty || _drawing.IsDirty; }
}
While iterating through the child objects in the BusinessListBase class, it returns true for IsDirty when it gets to the new Drawing object, but it returns false for IsDirty the last time through and that's what gets passed back to the overridden IsDirty property in the parent Project object.
Copyright (c) Marimer LLC