none
Specify CHANGE_TRACKING_CONTEXT prior to SaveChanges() RRS feed

  • Question

  • I am applying a number of changes and am using SQL Change Tracking. Is there any way to specify the CHANGE_TRACKING_CONTEXT to be applied to all inserts, updates and deletes that will occur when SaveChanges is called?
    Wednesday, August 31, 2011 8:21 AM

Answers

All replies

  • Turns out there is a great solution to intercept and mess around with EF commands however, it does not work with Code-First:

    Jarek Kowalski's EF Provider Wrappers would have done the trick nicely but they do not support database creation and can't be intermixed with the default Sql Server Provider.

    http://code.msdn.microsoft.com/EFProviderWrappers-c0b88f32

     

    The examples above intercept requests for tracing but could have very easily been modified to manage change tracking. Still looking for an EF4.1 way to intercept and modify CommandTexts

    Thursday, September 1, 2011 4:22 AM
  • Hello Narayan,

    Thanks for your post.

    According to your description,  I can't repro your scenario,  so could you please show me some code? However, I think you could try to attach the objects which is modified to the context again. And then call the  SaveChanges method. BY this way, I think you could submit your changes to the DataBase.

    Here is some useful explaination about this:

    http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/4d7e7254-1cf9-4349-b9f9-36ecb76d4a47

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [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.

    Monday, September 5, 2011 6:44 AM
    Moderator
  • Hi Jackie-Sun,

    I am not referring to change tracking by the DataContext object. I am referring to change tracking by SQL Server (and SQL Server Compact) as described here:

    http://msdn.microsoft.com/en-us/library/cc305322.aspx

    Here's a quote from the page:

    To track which client made a data change that is applied at the server, use the WITH CHANGE_TRACKING_CONTEXT clause. Before executing an INSERT, UPDATE, or DELETE statement, set the CHANGE_TRACKING_CONTEXT to the value of the @sync_client_id or @sync_client_id_binary session variable. This information is stored in the change tracking table so that applications can track the context under which a change was made. For Sync Framework, this is typically the client ID. However, you can store any value that fits in a varbinary(128) column.

     

     


    Wednesday, October 19, 2011 7:28 PM