Getting multiple requests when making a transaction, why?

public Parent GetByName(string Name)
{
    return _session.CreateCriteria<Parent>()
        .Add(Restrictions.Eq("Name", Name))
        .SetFetchMode("Children", FetchMode.Eager)
        .SetResultTransformer(new DistinctRootEntityResultTransformer())
        .UniqueResult<Parent>();
}

public ParentDetailVM GetMeAParent(string Name)
{
    Parent parent;
    using (var tx = _session.BeginTransaction())
    {
        //This works well, one single query loading
        //both parent and children
        parent = _parentRepository.GetByName(Name);

        //If I include this as suggested by NHProfiler
        //it all of the sudden sends a new query for each child
        //and a query for the grandchildren collection
        tx.Commit();
    }

    return Mapper.Map<Parent, ParentDetailVM>(parent);
}

I checked that nothing in the mapping files was configured to load. I can’t understand why it works if I move away from committing a transaction, but otherwise it issues N more requests. Does anyone know why this might happen?

+3
source share
1 answer

If you check _session.IsDirty()before making a transaction, my bet is that it will return true. When the transaction is completed, the session is cleared and for some reason the children are loaded to cascade the change.

, "ghosting" phantom. , nullable int, NULL. , NHibernate 0, .

- dynamic-update="true" XML-, DynamicUpdate() , , . Ghostbuster, .

0

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


All Articles