One DbContext per web request… why?

后端 未结 9 1236
死守一世寂寞
死守一世寂寞 2020-11-21 22:09

I have been reading a lot of articles explaining how to set up Entity Framework\'s DbContext so that only one is created and used per HTTP web request using var

9条回答
  •  悲&欢浪女
    2020-11-21 22:41

    What I like about it is that it aligns the unit-of-work (as the user sees it - i.e. a page submit) with the unit-of-work in the ORM sense.

    Therefore, you can make the entire page submission transactional, which you could not do if you were exposing CRUD methods with each creating a new context.

提交回复
热议问题