JP.
JP.

Reputation: 5606

NHibernate Queryover - How do I return only a child collection

I am running into difficulty with the following nhibernate queryover query. I am probably over-complicating things, but here is the problem:

I figured I could use something like the following to get back just the auctions, but because I'm querying over AuctionStatistic it expects the selected value to be of type AuctionStatistic (or a list thereof)

var auctions = _session.QueryOver<AuctionStatistic>().Where(c => c.ViewCount > 10000).Fetch(x=>x.Auction).Eager.Select(x=>x.Auction);

Can anyone suggest a better way of doing this?

Thanks

JP

Upvotes: 1

Views: 1744

Answers (1)

dotjoe
dotjoe

Reputation: 26940

Without bi-directional this is probably your best bet.

Auction auctionAlias = null;
AuctionDTO dto = null;

var auctionDtos = _session.QueryOver<AuctionStatistic>()
    .Where(c => c.ViewCount > 10000)
    .JoinAlias(x => x.Auction, () => auctionAlias)
    .SelectList(list => list
        .Select(() => auctionAlias.id).WithAlias(() => dto.id)
        .Select(() => auctionAlias.name).WithAlias(() => dto.name))
    .TransformUsing(Transformers.AliasToBean<AuctionDTO>())
    .List<AuctionDTO>();

Upvotes: 1

Related Questions