locked
Change Interceptor not firing for update RRS feed

  • Question

  • If I create a change interceptor for an entity, the change interceptor function gets called when a record of that entity is created via the .Net Dataservice. However, upon updating a record of the entity, the change interceptor does not get called even though querying the database afterwards shows that the update was made.

     

    Is this a bug? How do I get notified of an update?

     

    Regards,

    Michael

    Wednesday, July 9, 2008 7:20 AM

Answers

  • Apologies,

    the problem was in my code -  a property changing event handler in my entity was throwing an exception, so the data service did not get as far as invoking the change interceptor.

     

    It is working now.

     

    Sorry for the spurious query

    Graham

     

    Monday, September 22, 2008 9:28 AM

All replies

  • The changeinterceptor is called once per update/object. it should fire after the object is updated and before savechanges is called to commit the changes. Are you seeing something different? If yes, which bits are you using?

     

    Thanks

    Pratik

     

    Monday, July 14, 2008 5:12 PM
    Moderator
  • Hi Pratik,

     

    Thanks for responding. I am using the latest bits (I just downloaded the .net 3.5 sp1 beta 7/3/2008 to be sure). Here is the ChangeInterceptor definition:

     

    [ChangeInterceptor("item")]

    public void itemChanged(Model.item source, UpdateOperations action)

    {

     

    // If I set a breakpoint here it gets triggered when an "item" gets created. It doesn't get triggered if an item is updated even though the update is persisted in the database.

     

    if (action == UpdateOperations.Change)

    {

     

    // If I set a breakpoint here it never gets triggered

     

    }

    }

     

    Regards,

    Michael

    Tuesday, July 15, 2008 12:38 AM
  • Is this happening for anyone else? As a work around I'm having to develop service operations that I call to do updates so i can run some code when an object is updated. So my nice RESTful interface is now starting to look not so RESTful.
    Tuesday, July 22, 2008 4:44 AM
  •  

    Sorry for the late response. I tried this scenario, and this seems to work with the current bits. Can you please email me at pratikp@microsoft.com.donotspam (please remove donotspam from the end).

     

    I can send you the latest bits and you can tryout with those and let me know if that works for you.

     

    Also, can you please let me know what type of update you are doing? I tried updating a primitive property and that seemed to work. DId you update something different?

     

    Thanks

    Pratik

    Monday, July 28, 2008 4:15 PM
    Moderator
  • Michael,

    Same thing is happening with me. I have the following change interceptor declared:

    <ChangeInterceptor("CodePropAttributeTypes")> _
        Public Sub OnChangeCategories(ByVal p As PMonzaModelEntities.CodePropAttributeTypes, ByVal action As UpdateOperations)
            Try
                If action = UpdateOperations.Add Then
                    Throw New DataServiceException(400, "Test Error")
                ElseIf action = UpdateOperations.Change Then
                    Throw New DataServiceException(400, "Test Error")
                ElseIf action = UpdateOperations.Delete Then
                    Throw New DataServiceException(400, "Test Error")
                End If
            Catch ex As Exception
                Dim s As String = ""
            End Try
        End Sub

    The add and delete are firing just fine, but the the changeinterceptor is not being fired when an update takes place.  But the database is being updated.  Also - I am running the following client side when my datagrid is updated:

    Private Sub dgCAPT_CommittingEdit(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridEndingEditEventArgs) Handles dgCAPT.CommittingEdit
            Try
                Try
                    _entityProxy.AttachTo("CodePropAttributeTypes", dgCAPT.SelectedItem)
                Catch ex As Exception
                    'ignore error
                End Try
                _entityProxy.UpdateObject(e.Row.DataContext)
            Catch ex As Exception
                System.Windows.Browser.HtmlPage.Window.Alert(ex.Message & ControlChars.NewLine & ex.InnerException.Message)
            End Try
        End Sub




    Monday, August 4, 2008 5:50 PM
  • Same thing here, with .Net Framework 3.5 SP1 downloaded yesterday (august 4th 2008) with a simple service based on an EF model.

    Insert/Delete are caught, but not Updates, although the update DOES take place, datastore-wise.

    Any idea what could cause this?
    Tuesday, August 5, 2008 5:39 PM
  • Denis,

     

    Just to confirm: I am using 3.5 SP1 as well.

     

    Tuesday, August 5, 2008 5:45 PM
  • Hi Guys, we just released the RTM version of .NET 3.5 SP1.  Can you give this a spin with the latest bits?

     

    Links to downloads: http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx

     

    Tuesday, August 12, 2008 4:15 PM
  • I've upgraded my self to the latest Framework SP1 and VS2008 SP1. Unfortunately this release appears to be out of sync with the current Silverlight Tools for VS2008 Beta 2 and my ASync results are now broken.  Specifically here on the query.EndExecute(result) line.

     

    void OnCategoriesReady(IAsyncResult result) {

    DataServiceQuery<Categories> query = (DataServiceQuery<Categories>)result.AsyncState;

    IEnumerable<Categories> categories = query.EndExecute(result);

    foreach (Categories c in categories) {

    Debug.WriteLine("Silverlight: " + c.CategoryName);

    }

    }

     

     

    For those who may want to know more this problem is detailed in this thread: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3736840&SiteID=1

     

    I'd advise anyone who wants to keep working with Silverlight/Entity Framework to avoid SP1 RTM until the next Silverlight Tools release.

    Friday, August 15, 2008 2:26 PM
  • There is an interm fix for this issue that Microsoft has released:

    http://blogs.msdn.com/astoriateam/archive/2008/09/02/interim-release-making-sl2-beta-2-clients-work-with-net-fx-3-5-sp1-rtm-servers.aspx

    I've tested it on my stuff and I'm back in business
    Saturday, September 6, 2008 1:01 AM
  • Hi,

    I am having the same issue, ChangeInterceptor not firing for updates, with a simple Windows Application client using VS 2008 SP1 Release.

     

    Thanks

    Graham

     

     

    Friday, September 19, 2008 9:59 AM
  • Apologies,

    the problem was in my code -  a property changing event handler in my entity was throwing an exception, so the data service did not get as far as invoking the change interceptor.

     

    It is working now.

     

    Sorry for the spurious query

    Graham

     

    Monday, September 22, 2008 9:28 AM