I use db models using blocks so as not to be confused with utilities and any unmanaged resource requirements associated with them, but I want to know (mainly) what happens when the db model goes out of scope. The issue is not recycling or memory (I know he does it automatically for us). Question about connecting SQL and related instances.
So here is a simple example ( ActionResult ):
Account account; using(AccountsModel accountModel = new AccountsModel()) { account = accountsModel.Accounts.FirstOrDefault(x=> x.Username == username); if(account == null) return; account.Name = name; accountsModel.SaveChanges(); } ViewBag.Name = account.Name;
The question arises: "Is it safe to access an instance of the Account class (which is provided by AccountsModel ) from a model using a scope?"
Note: I know that I could not / could not / could not perform any update in the table out of scope.
source share