When I say this
using (Entities db = new Entities())
{
return db.TableName.AsQueryable().ToList();
}
Do I by-pass the functionality of using block since I return something, and the method exits before exiting the using block, so I think the using block will not serve to its purpose and dispose the resource.
Is this correct?
You are incorrect; it will be disposed.
The
usingstatement compiles to atry/finallyblock that disposes the original object in thefinallyblock.finallyblocks are always executed, even if the code inside thetryblock returned a value or threw an exception.