Is Deferred Execution in Asp.net MVC View a very bad thing?

前端 未结 4 797
遥遥无期
遥遥无期 2020-11-29 08:54

Let\'s say i have the following model which is obtained via Entity Framework:

public class User{
 public string Name {get;set;}
 public int Id {get;set;}
}
<         


        
4条回答
  •  清歌不尽
    2020-11-29 09:39

    Doing your way at least extends the life of the context with the risks (never certain but) :

    • db lock (cross contexts concurrency on db);
    • connexion pool failure: the connexion is given back to the pool when the context is disposed
    • "context no longer exists" exception in your view
    • ...

    keep your context scope as short as possible.

    by the way, from an mvc point of view, there is no reason for having the same model for view and data access. This is not a performance issue but a separation of concern issue, that is a maintainability issue.

提交回复
热议问题