I write a lot of VB.net web services that utilize Entity Framework & LINQ to return JSON data. Many times for shorthand I just return the data directly from inside the Using statement.
I can't help but wonder, is there any advantage to storing the return value and returning it outside of the Using statement?
The MSDN documentation on Using states:
" the Using block guarantees disposal of the resources, no matter how you exit the block. "
So I think this is just as acceptable, but I just want to make sure I'm not missing any potential problems.
Sample Code:
<WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Function GetListOfRows()
Try
Using CTX As New [EFContext]
Return (
From R In CTX.[Rows]
).ToList()
End Using
Catch Ex As Exception
'Capture & Report Error
End Try
End Function