none
Extending Context.OnSavingChanges with DBContext RRS feed

  • Question

  • Hi,

    We are working on and ASP.Net MVC3 project (C# / EF4.0), and we are almost half way through. I am looking to extend the OnContextCreated function and found very good ways to do it.

    Mainly:

        private void OnContextCreated()
        {
          this.SavingChanges += new System.EventHandler(mySavingChanges);
        }
    
        private void mySavingChanges(object sender, System.EventArgs e)
        {
          Console.WriteLine("SavingChanges fired");
        }
    


    The only issue is that it doesnt seem to work if I have DBContext code generated from the model, it works correctly without it.

    I am fairly new to EF and.Net in general, so this is a 2 part question:

    1. Is there a way to make it work with DBcontext?
    2. If no, and I am to remove the DBcontext code, will I lose any functionality or have to make any changes to my code (from a simple test Ive only found out that things like (.Add(..), .Remove(..), .Find(..), ..) will have different syntax, which i can live with.
    Saturday, August 6, 2011 8:21 AM

Answers

All replies