开发者

Return TSubType from nhibernate QueryOver

I am trying to select the children from a parent collection using QueryOver in nhibernate. This is what I am trying to do in HQL:

SELECT as_kitten FROM Cat as_Cat 
JOIN as_Cat.Kittens as_kitten 

How does this translate to QueryOver or even using JoinAlias?

IList&开发者_如何转开发lt;Kitten> kittens =  session.QueryOver<Cat>()
        .JoinQueryOver<Kitten>(c => c.Kittens)
        .Select(??)
        .List()

The closest thing I could find so far is NHibernate QueryOver

Cheers

EDIT Assuming this is a one way relationship, ie. kittens dont' know about cat


Your example seems rather trivial. If you already have the parent and have the collection mapped as a one to many inside your cat entity then all you would have to do if you were lazy loading is access the collection.

If you only have the id of the parent you could easily do something like this without even needing a join:

IList<Kitten> kittens =  session.QueryOver<Kitten>()
        .Where(k => k.CatId == <parent cat id here>)
        .List<Kitten>()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜