asp.net mvc - Using statement in Entity Framework -


i ask "using" statement in entity framework. saw several time in other forums , books, it's practice when quering database using following code (from asp.net mvc4 appliocation):

using (var db = new productsentites()) {    var result = db.products.tolist();    return view(result); } 

but in other hand, if using scaffolding generate contorller methods , view, default generator declaring

private productsentites db = new productsentites() 

at controller level, in case memory used store query results released when timeout usage expired , garbage collector unlock memory other needs. better small web site , best big

having

private productsentites db = new productsentites() 

as class variable , dispose in controllers dispose method seems fine me. mehmet ataş pointed out:

protected override void dispose(bool disposing) {     if(disposing)         db.dispose(); } 

the controller disposed after execution of action.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -