Get Original/Old Value For a Property

Get Original/Old Value For a Property

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


handaajay15 posted on Friday, June 13, 2008

In ADO DataRow world, We have the mechanism to get Original Value for any Column of the Row.

This is required in day-to-day business problems. We have to frequently compare before doing some processing the current value of the property  with Original Value of the property ( the value that was fetched from the database ).

This requirement is at both Server and Client Side.

Que: How Do I get the Original value of the property that was fetched from the database and compare that with current value of the property??

Any help / suggestion is highly appreciated.

Thanks

 

 

JoeFallon1 replied on Friday, June 13, 2008

You have 2 basic options.

Simply create some extra fields with ReadOnly Properties and when you set the value of Field1 during Fetch you also set the value of orig_Field1. This way you carry around the extra information and have access to it at any time. I do this for selected BOs and selected properties in those BOs. But not for all fields for all BOs.

As I recall the new managed properties can be extended to allow additional information to be carried around. This would include an Original Value. (And IsDirty for the the property itself which returns currVal <> OrigVal - which allows a value to be changed and then changed back to the orig inal value and thus state the Property itslef is not dirty even though the BO IsDirty.)

There is a huge thread on this topic - it was when Rocky first proposed it. I believe he concluded that he would not provide this type of information as a built-in part of CSLA but that he would allow CSLA to be extended for those developers who want this sort of thing. You'd have to find and review that thread ofr more details - unless some else can explain it more fully in this thread.

Joe

 

handaajay15 replied on Friday, June 13, 2008

Thanks for your reply Joe,

Keeping the old value with the property is an overhead as it doubles the size of the entity. You are right it should be done for specific required properties only. But some of the core tables we have like sales order or production order have more than 300 fields/properties each. and we need old values for a lot of them. So in WCF mode it becomes a huge overhead for serialization.

Theoratically Thinking:)

Client Side:

Can I create non-serializable client-side only dictionary or something more appropriate container, After fetch of the entity I can fill this dictionary and anytime when we need old value we can get the value from this dictionary.

Server Side:

I can compromise by re-fetching the entity from the database, fill my non-serializable server side only dictionary and provide the standard mechanism of getting the old value.

If the above theory is practically efficient to do, then Could you please provide me an example on how to do this.

Thanks.

 

 

 

ajj3085 replied on Friday, June 13, 2008

Sounds like it could be workable.. but it also sounds like pre-mature optimization, which is a design anti-pattern.  Personally I'd check Wcf to see if there's a way to compress the stream instead of adding more code to the problem.

Also, if you implement old values using the managed propety method, you should be able to use nullable types, and only store the value if it has actually changed.  That may reduce the size of the stream as well, and you could find out of the value ever changed since the BO was loaded.

handaajay15 replied on Friday, June 13, 2008

ajj3085:

Also, if you implement old values using the managed propety method, you should be able to use nullable types, and only store the value if it has actually changed.  That may reduce the size of the stream as well, and you could find out of the value ever changed since the BO was loaded.

Sounds good. Pardon my ignorance, Could you please provide one simple example for managed property method?

 

Copyright (c) Marimer LLC