我在我的MVC網站中使用實體框架,並使用using語句處理數據庫上下文。現在我的問題是如果我返回後關閉使用語句,數據庫上下文是否正確處理。例如:在MVC中使用語句處理數據庫上下文
public ActionResult SomeAction(){
using (var DB = new DatabaseContext()){
....
return View();
}
}
我必須返回之前關閉using語句?或者它會以我使用它的方式妥善處置。
這應該對你有所幫助:http://stackoverflow.com/questions/5381747/how-do-i-correctly-manage-the-disposing-of-a-datacontext – user2339071
你有什麼好。 http://stackoverflow.com/questions/6356307/will-a-idisposable-be-disposed-if-the-using-block-returns和http://stackoverflow.com/questions/7254815/dispose-and-return-網絡價值 –