Change Interceptor entity state is unchanged?! RRS feed

  • Question

  • I have the following change interceptor in my DataService




        Public Sub OnChangeRegistrations(ByVal reg As registration, ByVal operations As UpdateOperations)

                ConfigLogger.Instance.LogInfo("regID:" & reg.registrationID & operations.ToString )

                Dim objState1 As System.Data.Objects.ObjectStateEntry = Nothing

                If Me.CurrentDataSource.ObjectStateManager.TryGetObjectStateEntry(reg.EntityKey, objState1) Then


                End If



    It correctly  fires before an update on a registraion, as it should,  but the result of the log statements shows:







    But the entity did change and is updated by EF on this operation!  I want to do some work when certain fields change.


    Tuesday, November 22, 2011 10:56 PM

All replies

  • Hi Cool,


    To tell you truth, I'm not good at VB.net, but I think you should add byref in TryGetObjectStateEntry() method:


    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 23, 2011 7:32 AM
  • VB does that automatically by itself based on the declaration of the method, so in my example objState1 is being passed by ref.  

    A wierd thing is that this same code called in my context.SavingChanges handler works.  I think the problem has something to do with "Me.CurrentDataSource.ObjectStateManager".  

    To clarify, I have an Odata Dataservice. I am trying to act when a property of a registration entity has been changed and is being written to the database.  I assume that I can put this type of code in the registrations ChangeInterceptor.  

    From logging inside my CreateDataSource handler, I see that the Dataservice creates multiple Datasources.  I think the problem may be that within the ChangeInterceptor I am not getting the same datasource that created the initial entity and therefore the objectManager I am referencing does not see the changed properties.

    When a client does a put to update a registration via oData, how does the Dataservice coordinate and track the changes. Does the objectStateManager  retrieve the record from the database and  track property changes ?  

    Wednesday, November 23, 2011 1:36 PM
  • Perhaps a simpler question first.  At the first line of the ChangeInterceptor  (OnChangeRegistrations method) the value of reg does not contain the updated value!
    Wednesday, November 23, 2011 3:42 PM