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

Context Changing Event Issue

3 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joshua
Top achievements
Rank 1
Joshua asked on 20 Aug 2014, 04:07 PM
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

3 Answers, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 22 Aug 2014, 05:26 AM
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.
 
0
Joshua
Top achievements
Rank 1
answered on 21 Oct 2014, 01:07 PM
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
0
Kaloyan Nikolov
Telerik team
answered on 24 Oct 2014, 07:31 AM
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.
 
Tags
General Discussions
Asked by
Joshua
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Joshua
Top achievements
Rank 1
Share this question
or