DbContext Tracking issue

4 posts, 0 answers
  1. Jürgen
    Jürgen avatar
    1 posts
    Member since:
    Jan 2012

    Posted 09 Jul 2014 Link to this post

    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.


  2. Ady
    Admin
    Ady avatar
    588 posts

    Posted 09 Jul 2014 Link to this post

    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.
     
  3. DevCraft banner
  4. Bob
    Bob avatar
    10 posts
    Member since:
    Apr 2014

    Posted 05 Sep 2014 Link to this post

    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?
  5. Ady
    Admin
    Ady avatar
    588 posts

    Posted 10 Sep 2014 Link to this post

    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.
     
Back to Top