What is the difference between using these two perspectives such as references
public class MyController: Controller {MyContext DB = New MyContext (); Public Performance Index () {Return View (DB. Supers First (M = & gt; MID == 1)); } // <... or
Public class MyController: Controller {Public ActionResult Index} {(MyContext db = new MyContext () By)) {see return (db.Users.First (m = & gt; m.Id == 1)); }} // ...}
FYI, Created at reference controller level:
Public category MyController: Controller {MyContext db = new MyContext (); Public Performance Index () {Return View (DB. Supers First (M = & gt; MID == 1)); } // // // It is automatically called the framework, after // the ActionResult.ExecuteResult () is called. Protected Override Zero Dispos (Boiling Disposing) (If (Dipping & amp; DB! = Null) {db.Dispose ();} Base.Dispose (Disposal);}} Perform Visual After being called the controller's settlement method, it will allow you to call a deferred property in your view (disposal of dbcontext) within that action (IQueryables, Lazy-loaded properties) that will not allow that (second example). In the example, any speech of deferred verbs The exception will give you an exception.
No comments:
Post a Comment