Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to instantiate and dispose DbContext in MVC?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COUsing block approach is having some disadvantages. It causes a lot of round trips to database and misuse of transactions in Entity framework. refer http://ayende.com/blog/4775/new-profiler-feature-avoid-writes-from-multiple-sessions-in-the-same-request
      singulars
    2. COWhy does it cause more roundtrips? One http request supposed to run one action in most cases,so if you wrap the whole action's code into this using block there would not be more database requests comparing to 1st approach. The other thing with the 'per action' approach is that you should always be aware of a scope the database might be invoked in and put the block appropriately. For example if your model contains some collection to be lazy loaded in a time View rendering, statement returning View(Model) should be inside the block.
      singulars
    3. COIf you use DbContext in controller layer wrap with UnitOfWork creates strong dependency in UI Layer and your database approach. Then you need a Service Layer and Repository Layer. After that if your repositories have separate UnitOfWork with using blocks that will be a problem. because each and every repository creates transactions and unnecessary database round trips. See above link for more detail. if you sure about one service call per request then you can use unitofwork inside of service method.However, It is not guaranty.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload