开发者

Return TSubType from nhibernate QueryOver

开发者 https://www.devze.com 2023-03-21 23:16 出处:网络
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:

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

精彩评论

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

关注公众号