will situation 1 and/or 2 cause it to sit around waiting for GC. I find that the context being used multiple times is causing our code to have methods that have nothing but a using block and I'd like to avoid the using block in those cases if the context will get disposed quickly enough. An example would be a method which does some saving and opens up the context -> saves data to multiple tables -> then returns 200 OK.
Situation 1
public function test()
{
return new myContext().Events.FirstOrDefault();
}
Situation 2
public function test2()
{
var ctx = new myContext();
return ctx.Events.FirstOrDefault();
}
Situation 3
public function test3()
{
Event e;
using(var ctx = new myContext()) {
e = ctx.Events.FirstOrDefault();
}
return e;
}