c# - 'The operation cannot be completed because the DbContext has been disposed' - after adding Dispose() -


i getting above error on various controller actions after adding line....

protected override void dispose(bool disposing)         {             repo.dispose();             base.dispose(disposing);         } 

...to controller. before adding line had issue dbcontext returning old or cached data after record update operation. seems fixed, i'm having 'dbcontext has been disposed' issue. controller looks this...

public class casestoreviewcontroller : controller     {         private casereviewrepository repo;          public casestoreviewcontroller()         {             repo = new casereviewrepository(dataaccess.current);         }      protected override void dispose(bool disposing)             {                 repo.dispose();                 base.dispose(disposing);             }     } 

repository looks this...

 public class casereviewrepository : idisposable     {         private hsadbcontext _db;          public casereviewrepository(hsadbcontext db)         {             _db = db;         }  private bool disposed = false;          protected virtual void dispose(bool disposing)         {             if (!this.disposed)             {                 if (disposing)                 {                     _db.dispose();                 }             }             this.disposed = true;         }          public void dispose()         {             dispose(true);             gc.suppressfinalize(this);         }     } 

dataaccess.current ninject binding. i'm not sure how of can post because it's not code, seems work fine in other controllers project i'm working on, , change in errors after adding dispose() function contoller makes me think issue way implemented idispoable.

stepping through debugger see context getting disposed between time created in controller constructor , time repository method entered. when execution leaves scope of controller context disposed. how dispose() method works? , if need remove dispose() implementation constructor?


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -