entity framework - Using Block in Asp.net -


i have doubt using(){}. know uses idisposable interface. if write in linq entities:

using(objectconext context=new objectcontext()) {    throw new exception(); } 

will objectcontext still disposed , existing connection closed or remain there alive. thanks, gaurav

the using statement expands try finally block. when exception thrown, finally block in using statement should execute.

from http://msdn.microsoft.com/en-us/library/yh598w02.aspx:

the using statement ensures dispose called if exception occurs while calling methods on object.

what happens next matter. spender points out in answer, datacontext has no obligation close connection using, nor need concerned (since datacontext should manage connection you).

under conditions, thrown exception can swallowed silently try finally block. see here: http://www.digitallycreated.net/blog/51/c%23-using-blocks-can-swallow-exceptions. shouldn't affect you, though.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -