I am running into difficulty with the following nhibernate queryover query. I am probably over-complicating things, but here is the problem:
- I have an entity named AuctionStatistic that links to an auction (this is uni-directional and I do not have links from auctions back to statistics)
- I would like to query the statistic table, find all auction IDs and pull back only those that meet a certain threshold – i.e. top 500 auctions by views
- Once I’ve gotten the top X (in this example i’m hardcoding to 10000 views) I want to pull back the auction id and name. For this particular query I don’t need any of the data stored in the statistics table (though this is used elsewhere and is not redundant)
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
Without bi-directional this is probably your best bet.