Issue with IsDirty on a grandchild object

Issue with IsDirty on a grandchild object

Old forum URL: forums.lhotka.net/forums/t/2884.aspx


RikGarner posted on Wednesday, May 16, 2007

I seem to be having a problem seeing IsDirty propogated up through a three level hierarchy.

Root object has a child list of sections; each section has a child list of items.

Tests look like this, only the first two pass.

cce.SectionsList[0].ItemList[0].State1 = true;

Assert.IsTrue(cce.SectionsList[0].ItemList[0].IsDirty);

Assert.IsTrue(cce.SectionsList[0].ItemList.IsDirty);

Assert.IsTrue(cce.SectionsList.IsDirty);

Assert.IsTrue(cce.SectionsList[0].IsDirty);

Do I need to override the default Save behaviour to make this work?

 

RockfordLhotka replied on Wednesday, May 16, 2007

You don't override Save - you override IsDirty and IsValid for any parent class, so it includes it children in the result.

RikGarner replied on Monday, May 21, 2007

Excellent - it works now!

As an aside, in the template code that updates a collection, it checks IsNew to determine whether to Insert, but it doesn't check IsDirty before doing an Update. Can I add that check as an optimisation, or is there a hidden side effect that it might introduce?

I've just thought about this some more - is it sensitive to whether I'm in the 'youngest' (i.e. bottommost) collection in the hierachy?

RockfordLhotka replied on Monday, May 21, 2007

You can certainly have your collection check IsDirty. I typically have the child object itself do that check, but either place works.

 

Rocky


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.6/813 - Release Date: 5/20/2007 7:54 AM

Copyright (c) Marimer LLC