Using Castle ActiveRecord, I ran into a problem with lazy loading.
The following works (obviously)
using (new SessionScope()) { User singleUser = User.FindFirst(...) UserGroup groups = singleUser.Groups;
Since I need to change session filters in a specific context (using interceptors), I create a new SessionScope.
using (new SessionScope()) { User singleUser; EnableVariousFiltersInThisThread(); using (new SessionScope()) { singleUser = User.FindFirst(...); } DisableVariousFiltersInThisThread(); UserGroup groups = singleUser.Groups;
The last line of “singleUser.Groups” throws a LazyInitializationException: “failed to lazily initialize the role collection: groups, session or session closed”.
However, all other session operations work correctly. Thus, it seems that "singleUser" is tied to an already installed SessionScope. What for? And how can this be solved alternatively?
source share