How to apply transaction isolation level for MVC app with lazy-loading is on?
We have web MVC app where EF's DbContext (POCO) derived class is managed by StructureMap and set up as http-scoped life-cycle. How can we set up specific isolation level for our repository (for instance Read Uncommitted) with lazy-loading is on? Isolation level is usually set up by TransactionScope which is disposable and not supposed to live for the entire Http request like DbContext is. Our controllers know nothing about all this Database specific stuff and work with repositories on开发者_高级运维ly, however ViewModel can automatically initiate Db queries by accessing lazy-loaded properties. Thank for any ideas.
You can create custom action filter which will use transaction scope with read uncommitted and use that action filter for actions where you want this behavior. Transaction is not bound to repository. Transaction is started either by controller or used service layer because business logic defines boundary of the transaction.
精彩评论