This is a migrated thread and some comments may be shown as answers.

Recursive change tracking

3 Answers 72 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jay
Top achievements
Rank 1
Jay asked on 22 Sep 2009, 02:52 PM
I want to set a LastUpdated property on my objects whenever they change but when I do this using the change tracking api, I end up with recursive calls that eventually cause a stack overflow.  Is there a way to temporarily turn off change tracking or some other way to accomplish what I want to do?  Here's a look at the code that doesn't work.

        static void Tracking_Changed(object sender, ChangeEventArgs e) 
        { 
            IDomainObject obj = e.PersistentObject as IDomainObject; 
            if (obj != null
            { 
                obj.LastUpdated = DateTime.Now; 
            } 
        } 

3 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 23 Sep 2009, 09:30 AM
Hi Ben Friedman,

There are few possible solutions to your problem. In order to find the right one, we would require a bit more information on what are you trying to achieve. Are you going to use this value for concurrency control or is it just for information? Are you intending to have this value set whenever a property is changed inside a transaction, or do you want to have the value of the time when the object was last updated in the database?

We are looking forward for your next ticket. Thanks for the collaboration.

Greetings,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jay
Top achievements
Rank 1
answered on 23 Sep 2009, 02:03 PM
Hi Zoran

This value will just be for informational purposes and it really doesn't matter whether it reflects the time at which the property was changed or when the database was updated.  Which ever solution is easiest, though it would be nice to see how to do both.

Thanks!
0
Zoran
Telerik team
answered on 25 Sep 2009, 12:37 PM
Hello Ben Friedman,

In this case i would suggest you some of the best practices for the purpose. You should implement the IInstanceCallbacks interface on the persistent class that you want to keep track of. One of the IInstanceCallbacks members is the PreStore() method.

This method is called just before an object gets stored into the database. There you can check if an object has been updated and apply your logic.
    public void PreStore() 
        { 
            IObjectContext scope = Database.GetContext(this); 
            if (scope.IsDirty(this)) 
            { 
                this.LastUpdated = DateTime.Now; 
            } 
        } 


Regards,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Development (API, general questions)
Asked by
Jay
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Jay
Top achievements
Rank 1
Share this question
or