What is the correct way to use nhibernate transactions and second level cache on an asp.net-mvc page?

StackOverflow https://stackoverflow.com/questions/22904262

문제

I have a number of pages that run 10 t0 15 different queries to build up a page. I see from a few articles, to have nhibernate second level cache working I need to use transactions.

So I want to confirm that i should be putting all of those 10 to 15 queries inside a single transaction? something like this?

    var session = Repository.Session;
    using (var tx = session.BeginTransaction())
     {
           var viewModel = new ViewModel();
           viewModel.Cars  = session.Query<Car>();
           viewModel.Dogs = session.Query<Dog>();
           viewModel.Cats  = session.Query<Cat>();
           viewModel.Birds  = session.Query<Bird>();
            tx.Commit();
      }
도움이 되었습니까?

해결책

The queries do not need to be executed in the same transaction but there's no reason not to. That is, it's not necessary but it's more work to do it any other way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top