In the application that I inherited there, it is in the base controller, which inherits every other controller in the application.
public BaseController() { db = new MyDbContext(); db.Database.Log = s => Debug.Write(s); } public MyDbContext() : base("name=MyDbContext") {
Due to how the application was developed, at least 2 contexts are created upon request. (This MVC application is the call to HomeController on every page, plus any other controllers called for a particular page.)
My question is when DbContext create a connection to SQL Server? Is it right when the context is created, or only when the request is executed?
If this is the first, then I will use 2 times twice as many connections to the SQL server as necessary, and if this is the last, then this is probably not a very big problem.
I do not think that I can reorganize this in the near future, of course, not without justification. What are the potential pitfalls of this project I should know?
Entity Framework 6.1.3
source share