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

DbContext Tracking issue

3 Answers 70 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.
Jürgen
Top achievements
Rank 1
Jürgen asked on 09 Jul 2014, 08:45 AM
I want to deal with "Tracking Context Changes" http://docs.telerik.com/data-access/feature-reference/api/context-api/feature-ref-api-context-api-tracking-context-changes
Unfortunately oldValue and newValue are always null. PersistentObject and PropertyName are allright.

private void Events_Changed(object sender, Telerik.OpenAccess.ChangeEventArgs e)
{
// Getting the modified object.
object modifiedObject = e.PersistentObject;

// Getting the modified property name.
string modifiedPropertyName = e.PropertyName;

// Getting the new value.
object newValue = e.NewValue;

// Getting the old value.
object oldValue = e.OldValue;
}

Anybody using this feature can help.

Thanx in advance.


3 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 09 Jul 2014, 02:37 PM
Hi Jürgen,

If the property getter is not accessed before it is modified and it is not a value field then the OldValue will be null since the value is not loaded from the database, but the NewValue should not be null.

Can you send some sample code that shows the problem? This will help in resolving the issue sooner.

Regards,
Ady
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Bob
Top achievements
Rank 2
answered on 05 Sep 2014, 10:00 PM
I get the same thing when the Property is a Navigation Property using a join table (for a many to many relationship).  Has anyone found a way to track these changes?
0
Ady
Telerik team
answered on 10 Sep 2014, 10:02 AM
Hello Bob,

 When you add a new instance to a collection property you are changing an object that is already added to the context. This will fire  the Changed event of the context. Since the change occurs in a collection, there is no old or new value. This behavior is expected as changes to the collection navigation properties of persistent objects need to be handled in a different manner.

To handle changes made to the collection navigation properties, you will need to modify their type to be TrackedBindingList. You can see how to do this in this article. TrackedBindingList is an extension of BindingList and therefore exposes the same events. You can subscribe to those events to handle changes as needed. Please find attached a project which demonstrates how this can be done.


Additionally keep in mind that in order for the ListChanged event to be raised, the type that the list will contain (Child in this case) needs to implement the INotifyPropertyChanged interface. You can implement this interface in your entities automatically as show in this article.

Do get back in case you need further assistance

Regards,
Ady
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Development (API, general questions)
Asked by
Jürgen
Top achievements
Rank 1
Answers by
Ady
Telerik team
Bob
Top achievements
Rank 2
Share this question
or