我遇到了以下nhibernate查询转移查询的困难。我可能过于复杂了,但问题出在这里:
我想我可以使用类似下面的内容来回到拍卖会,但因为我在查询AuctionStatistic时它希望所选的值是AuctionStatistic类型(或其列表)
var auctions = _session.QueryOver<AuctionStatistic>().Where(c => c.ViewCount > 10000).Fetch(x=>x.Auction).Eager.Select(x=>x.Auction);
有人能建议更好的方法吗?
由于
JP
答案 0 :(得分:1)
如果没有双向,这可能是你最好的选择。
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>();