Context Changing Event Issue

4 posts, 0 answers
  1. Joshua
    Joshua avatar
    5 posts
    Member since:
    Jul 2012

    Posted 20 Aug 2014 Link to this post

    Hey Guys,
    I just updated to 2014.2.711.1, and it appears that the context.Events.Changing/ed events do not work as they did previously.  If a property is not accessed before it is changed, then the OldValue property in the ChangeEventArgs will be null and marked not loaded.

    I was able to work around this by using the changing event instead, and then using reflection to get the old value, but is there a better option I am missing? Is this a bug, or the expected behavior?

    Thanks!
    -Josh
  2. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 22 Aug 2014 Link to this post

    Hi Josh,

    We are aware of this issue and it is logged in our bug tracking system.  

    Your workaround is valid but instead of using reflection to read the old value I would suggest you the following alternative:
    static void Main(string[] args)
    {
        using (EntitiesModel1 dbContext = new EntitiesModel1())
        {
            dbContext.Events.Changing += Events_Changing;
     
            var customer = dbContext.Customers.FirstOrDefault();
     
            customer.CompanyName = "Telerik";
        }
    }
     
    static void Events_Changing(object sender, Telerik.OpenAccess.ChangeEventArgs e)
    {
        var context = sender as OpenAccessContext;
     
        object oldValue = context.GetOriginalValue<object>(e.PersistentObject, e.PropertyName);
    }
     It should be faster compared to reflection because the GetOriginalValues accesses directly the underlying objects storing the values and doesn't perform any reflection. The only disadvantage here is that the method is generic and you should know the type upfront. In my example above I am using <object> but this will result in not needed boxing. Probably in your implementation you can use switch based on the type to be more optimal. 

    Would it be possible to share with us which is the previous version that was working for you in this scenario?

    I hope this helps. Should you have any additional questions do not hesitate to get back to us. 


    Regards,
    Kaloyan Nikolov
    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. Joshua
    Joshua avatar
    5 posts
    Member since:
    Jul 2012

    Posted 21 Oct 2014 in reply to Kaloyan Nikolov Link to this post

    Hey Kaloyan,
    Sorry for the delayed reply - I totally missed your your question when i read this response originally.  We upgraded from 2014.1.403.2, everything worked as expected for us in that version.

    Hope this helps!
    Regards,
    Josh
  5. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 24 Oct 2014 Link to this post

    Hello Joshua,

    The actual bug is that if you haven't visited the property once before setting a new value the OldValue in the  dbContext.Events.Changing event is not populated. This is a known issue logged in our bug tracking system. 

    Unfortunately I cannot give an exact time frame when you could expect to be fixed. I am sorry for the inconvenience caused. 

    Regards,
    Kaloyan Nikolov
    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