StrataFrame Forum

Transaction & IsDirty

http://forum.strataframe.net/Topic15765.aspx

By Crones - 4/18/2008

So here is the scenario:



I have an inherited BO that generates an "AutoID" value based on other field values. This ONLY happens when a new record is created. Now what happens is during the very FIRST save, my BO creates a transaction and saves the record using a temporary value for the AutoID so I can retrieve the PrimaryKey value, and then update the AutoID value with the field values I need and re-save just the AutoID value using a command object. Once this completes the transaction is committed. (Subsequent saves doe not automatically use a transaction unless I tell it too.) So far, everything works great and I have a happy day continuing on my way. Now the kicker:



In my case I generally open a form, fill just the data I need, make a change, save and close. When opening the form again (thus refilling the BO) and make a change, save & close everything is fine and dandy, HOWEVER, if I open the form, create a NEW record, save and do NOT close the form, and begin modifying data and save again, my changes are NOT pushed back to the database. I traced this to the Base BusinessLayer's save event and checking on the IsDirty property which returns FALSE if _IsSavedOnTransaction is set to TRUE which happened because I initially saved the BO in a transaction but do not need to save in a transaction again.



My question here would be: Is there some way to reset the BO's _IsSavedOnTransaction property to false without refilling the data?
By Trent L. Taylor - 4/21/2008

We actually use transactions quite a bit in our medical app and so I know that it will work.  Now we did recently make a change to the transactions when dealing with foreign key values.  However, in you case I am a little confused as to what is going on...I didn't totally follow what you were trying to do.  The private that you are talking about cannot be access outside of the BusinessLayer.  However, if you create an inherited BO from BusinessLayer you should be able to get to that field (if nothing else through reflection).  But I would be more interested in what you are doing versus just trying to set that value as I think that just setting that will cause some other side-effects down stream.
By Crones - 4/21/2008

The best way of describing what I'm doing is to just upload a test project.



To test what is happening, start the app, fill in the First & Last Name, then click save.

The AutoID should update itself to be the first 4 letters of the last name, first letter of the first name and a padded employeeid.

Now, after that first record, if you were to create another new record (or edit the existing one) and save the changes, nothing get saved because the StrataFrame's base business object checks if the bo was saved in a transaction and exits without saving again.



By looking at the Before & After save events in the BaseAutoIDFormatBusinessObject, it shows how I am "pre-saving" the object in a transaction if one is not defined, so that I can get the EmployeeID from the database and then updates the AutoID field using a command against the same transaction. Once that is completed, the transaction is committed.
By Crones - 4/24/2008

Just a bump to see if there is a better way to handle this. ;-)
By Crones - 4/24/2008

Thank the [deity] for source code!!! w00t



Found a bug in the StrataFrame BusinessLayer.

In the BusinessLayer's save method the existing code is:



If Transactional Then

...

If _BosOnTransaction.TryGetValue(Me._DataSourceKey & "|" & Transactional, list) ...

...

End If



Which should be:



If Transactional Then

...

If _BosOnTransaction.TryGetValue(Me._DataSourceKey & "|" & TransactionKey, list) ...

...

End If



I changed this, compiled and ran it and everything worked as expected.




By Trent L. Taylor - 4/24/2008

I will take a look at this in the morning and make sure that there isn't something else that was missed.  Good job and thanks for the tip.  Sorry I didn't get to this sooner Blush I have been running around with 1000 things up in the air this week...it was on my list but I just had not gotten to it...out of the norm for us, but I am glad that you got it going!
By Trent L. Taylor - 4/25/2008

Yup, it was a bug.  Good catch.  I have made the changes and it will be corrected in the next build posted.  Thanks!!!
By Crones - 4/25/2008

Not a problem. And thank you for such a great product. Makes life so much easier.
By Trent L. Taylor - 4/25/2008

Thanks for your kind words!  Smile