Lazy looking up dictionary value using stateless session

In my application, I set up triple dictionary matching so that for this user I can get "settings" for each instance of the object owned by the user. That is, I have something like:

public class User
{
    public virtual IDictionary<Baz, BazSettings> BazSettings { get; set; }

    //...

Therefore, whenever I have an object Baz, I can find the current baz user settings through currentUser.BazSettings[baz].

I would like to be able to use a stateless session for this, but I get LazyInitializationExceptionwith this code:

//int bazId;
using (IStatelessSession session = Global.SessionFactory.OpenStatelessSession())
{
    var currentUser = session.Get<User>(Membership.GetUser().ProviderUserKey);
    var baz = session.Get<Baz>(bazId);
    var bazSettings = currentUser.BazSettings[baz]; // raises `LazyInitializationException`

When I use instead ISession, the problem disappears.

NHibernate "no session session was closed". , . , .

currentUser.BazSettings[baz]?

+3
2

, , : , .

- . , , ?

0

ISession IStatelessSession, , , , .

0

Source: https://habr.com/ru/post/1787349/


All Articles