Perhaps a simple question but I can’t find the answer. I have a web form in which I declare my dbContext. However, when the page does postback, it overwrites the dbContext and I lose my object tracking. How do I keep the dbContext secure from changes until I’m ready to dispose of it?
Share
The suggested pattern for using DbContext is to instantiate a new DbContext per HTTP request, and use that instance for the duration of that particular request.
You should not be attempting to keep an instance of DbContext across HTTP requests.