Problem overriding IsDirty

Problem overriding IsDirty

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


kilroy posted on Tuesday, February 20, 2007

All:

I'm having a time overriding IsDirty in a root BO derived from BusinessBase<T>. This object contains, as do all real-world BOs, other objects, and to check the IsDirty flag of this object I must override IsDirty. Problem is, my base.IsDirty always returns true, no matter what. Here is the code for the override:

        public override bool IsDirty {
            get {
                return (base.IsDirty || (mvarDCSEContact != null && mvarDCSEContact.IsDirty) ||
                       (mvarStateContact != null && mvarStateContact.IsDirty) || mDefendants.IsDirty ||
                       mPlaintiffs.IsDirty || (mvarOrders != null && mvarOrders.IsDirty) ||
                       (mvarChildren != null && Children.IsDirty) || mvarAPAID != 0 || mvarTechID != 0);
            }
        }




Here is the update procedure for the object:

        protected override void DataPortal_Update() {
            using (NpgsqlConnection cn = new NpgsqlConnection(Program.getConnectionStr())) {
                cn.Open();

                if (IsDirty) {
                    ExecuteUpdate(cn);
                    MarkOld();
                }

                //update child object(s)
                UpdateChildren(cn);
            } //using
        }

Even after the MarkOld() call, I can inspect the IsDirty property and it shows true. The interesting thing is, I can trace into the property calls, all the way down to BusinessBase.IsDirty, and the _isDirty flag itself is false, but when it returns, the property is True.

Thanks in advance for any help....


xal replied on Tuesday, February 20, 2007

Try removing the override. Maybe it's one of the children that's returning True...
How are you fetching the data? directly into the fields or through their properties?  If it's the latter, then your object will be marked dirty upon loading.


Andrés

kilroy replied on Tuesday, February 20, 2007

No, none of the children are returning true. I hover my cursor over the base.IsDirty variable and it shows up as true, and when I hover over the others they all return false.

I'm fetching the data directly into the fields. However, after executing ExecuteUpdate() in the DataPortal_Update method, and calling MarkOld(), it shouldn't matter how the data got there, _isDirty should be false, and the property IsDirty should be false. That is not the case here. If I place a breakpoint right after the MarkOld() call, the busines object's Isdirty property is still true.




pat replied on Monday, February 26, 2007

I had a similar problem: I found, that the debugger or ide is cheating me in these cases: it shows obviously wrong data. to help me out here, (temporarily to find out what happens exactly) I made one dirty-variable for each business object to find out which is really dirty.

patrik

Copyright (c) Marimer LLC