locked
How to override SaveChanges method RRS feed

  • Question

  • I want to know is there a way can override SaveChanges method? So I can add some my own logic before hitting database.
    Monday, May 21, 2012 9:35 AM

Answers

  • Hi,

    Try http://msdn.microsoft.com/en-us/library/cc716714.aspx (shows how to override SaveChanges or to subscribe to SavingChanges). Some more context could help (if you are using DbContext, you'll have only the first option ; as it seems you know you should override SaveChanges i f you have tried something that doesn't work it could be better to start from there)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Monday, May 21, 2012 9:53 AM

All replies

  • Hi,

    Try http://msdn.microsoft.com/en-us/library/cc716714.aspx (shows how to override SaveChanges or to subscribe to SavingChanges). Some more context could help (if you are using DbContext, you'll have only the first option ; as it seems you know you should override SaveChanges i f you have tried something that doesn't work it could be better to start from there)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Monday, May 21, 2012 9:53 AM
  • FWIW, the linked to article on MSDN ("How to: Execute Business Logic When Saving Changes") mentions 2 examples, but I couldn't find them in the article.

    Rod

    Wednesday, May 4, 2016 7:42 PM