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 using
statement compiles to a try
/ finally
block that disposes the original object in the finally
block.finally
blocks are always executed, even if the code inside the try
block returned a value or threw an exception.
using
statement will call Dispose
of db object before value returning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With