简体   繁体   中英

Filter child collection using a child collection of the child

Err, I can't think of better title. Basically I have a class called MarketGroups, this has a child collection Markgroups that has a collection of MarketTypes and MarketTypes has a collection of MetaGroups.

I would like to be able to, in one query, load the Parent, and only return Child MarketGroups that have MarketTypes with one specific MetaGroup in its MetaGroup collection.

I am aware of this question: Filter child collection returned with Aggregate Root using Nhibernate but is not the solution I'm looking for, I want to do this in code ideally as one query, but I wouldn't mind splitting it.

:)

Unless you restrict the children that are loaded by default (using the method you linked to) you'll have to load the Parent in one query and the children in another. AFAIK there's no way to query an object and have only certain children loaded.

You could always use MultiQuery to submit them at the same time mind you.

HQL something like (this may be missing the mark a bit):

            select
                mt
            from 
                MarketGroup mg
            inner join
                mg.MarketTypes mt
            inner join
                mt.MetaGroups mg
            where 
               mg.ID=12312 and mg.ID=3214123

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM