MVC 4, EF 4.3 Managing context during the lifecycle of an Application Request
问题 Situation: What I'd like to do is have access to the data context for the life cycle of a page. This is primarily to (a) avoid series of using() and to avoid (b) out of scope exceptions in the view when a lazy loaded property is accessed. Edit: I'm using MVC 4 and Entity Framework 4.3.1 (the latest) What I typically do is using (MyDB b = new MyDB()) { ...do all my stuff } In my controller or the data layer. The nice thing about this, based on my reading, is it's clean, causes no memory leaks