We're having an issue where I work. When we try to access a lazy loaded property on an NHibernate entity from within an MVC3 view, a "No Session" LazyInitializationException will be thrown. This only started cropping up on us in the last week, but we've been unable to narrow down the problem. There doesn't look like there's a simple solution though.
Notes:
- Example of stacktrace: http://textsnip.com/613608
- We don't Dispose(or wrap the Session in a using) anywhere in our projects. We let ObjectFactory handle that.
- This only happens on our TeamCity testing environment when running regression tests(SpecFlow with WatiN). None of us are able to reproduce the problem on our dev machines.
- This also doesn't happen consistently. While the tests that fail are usually the same tests, they don't fail all the time. Other tests that access pages that would hit some of the same views don't fail.
- On the tests that do fail, they seem to weigh more towards lazy loaded collection initializing than non-collection, but both do happen.
- While I know that it'd be better to eager load the entities whenever it's possible, due to the interdependency of a lot of our table models, it's not all that feasible at the moment.
What are we missing here?