I found a tutorial in microsoft asp.net website, that make an instance from context like this:
public class HomeController : Controller
{
private MoviesDBEntities _db = new MoviesDBEntities();
public ActionResult Index()
{
return View(_db.MovieSet.ToList());
}
...
}
this means each time controller instantiate, context will be instantiate too. but Here i was found that correct way to instantiate context is like this:
public class HomeController : Controller
{
public ActionResult Index()
{
using(MoviesDBEntities _db = new MoviesDBEntities()){
return View(_db.MovieSet.ToList());
}
}
...
}
so the question is, Which way is true? or is it important at all?