Initializing collections without fetching parents

44 views
Skip to first unread message

Tobias Eriksson

unread,
Dec 28, 2020, 4:11:32 AM12/28/20
to nhusers
Hi,
Is it possible to initialize collections without fetching parents?

For example with following mapping

public class EntityAMap : ClassMapping<EntityA>
{
    public EntityAMap()
    {
        Id(m => m.Id);
        Bag(m => m.OneToManyB, cm =>
        {                
            cm.Inverse(true);
        }, m => m.OneToMany());
    }   
}

I want to fetch OneToManyB for several parents.
The closest I have come is using ChildFetch


session.QueryOver<EntityA>()
                .Fetch(SelectMode.ChildFetch, e => e)
                .Fetch(SelectMode.Fetch, e => e.OneToManyB)
                .Where(e => e.Id.IsIn(ids))
                .List();

but then there still is an unnecessary join with the parent table

SELECT this_.id                as id1_0_1_,
       onetomanyb2_.Parent     as parent2_2_3_,
       onetomanyb2_.id         as id1_2_3_
FROM   EntityA this_
       left outer join EntityB onetomanyb2_
         on this_.id = onetomanyb2_.Parent
WHERE  this_.id in (1,2,3)


Gunnar Liljas

unread,
Dec 28, 2020, 6:57:18 AM12/28/20
to nhu...@googlegroups.com
"I want to fetch OneToManyB for several parents."

..or rather, you want to fetch EntityB:s where the Parent.Id is in a list. Make the query like that, instead of using fetches etc.

/G


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/adc83311-4f4a-4048-bdb9-87cf28e8d23dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages