开发者

NHibernate many 2 many query, returning all of one side and its children

Family and Parents is a m:m relationship.

Right now I have this query:

    public Family GetFamilyByParentId(long parentId)
    {
        queryString = @"select f
                        from Family f
                        join fetch f.Parents p
                        join fetch p.Person per
                        where p.Id = :id";

        return Session.CreateQuery(queryString)
                 开发者_开发知识库   .SetInt64("id", parentId)
                    .UniqueResult<Family>();
    }

This works fine, gets me the Family by one of the other side's parentIds. The problem is this query only loads a single parent. I need it to return all of the Family's parents.

I need to use some type of subquery for this right?


select f
from Family f
join fetch f.Parents p
join fetch p.Person per
where f.Id IN (select sub.Id 
            from Family sub join sub.Parents subP join subP.Person subPer 
            where subPer.Id = :id)

I think that will load all of the parents

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜