无法在 Nhb 4 中仅将某些字段构建为 select 的 2 个表 JOIN

Can't build 2 tables JOIN with only certain fields to select in Nhb 4

我尝试 运行 使用 Nhibernate v.4 进行这样的查询:

Select o.Number, c.Address
From Order o join Client c on o.ClientId = c.Id
Where c.Name = "John"

使用 JoinQueryOver 和 JoinAlias 尝试了很多方法,但无济于事,最终出现错误 "could not resolve property: Address of Order"

Session.QueryOver<Order>()
                    .JoinQueryOver(s => s.Client)
                    .Where(() => c.Name == "John")
                .SelectList(x => .Select(Projections.Property<Order>(o => o.Number)
                .SelectList(x => .Select(Projections.Property<Order>(o => o.Client.Address))

或者像这样

...
.SelectList(x => .Select(Projections.Property<Order>(o => o.Number)
.SelectList(x => .Select(Projections.Property<Client>(c => c.Address))

构建查询的正确方法是什么或非常相似的方法? 'Select' 运算符有问题,'Where' 部分工作正常。我还可以通过这两个彼此分开的实体构建非连接查询并且效果很好,但不知道如何连接它们

我终于想出了如何让它发挥作用:

Client client = null;
OrderClientDto dto = null;

var result = Session.QueryOver<Order>()
                    .JoinAlias(o => o.Client, () => client)
                    .Where(() => c.Name == "John")
                    .SelectList(x => x
                        .Select(o => o.Number).WithAlias(() => dto.Number)
                        .Select(() => o.Client.Address).WithAlias(() => dto.Address))
.TransformUsing(Transformers.AliasToBean<OrderClientDto>())
                        .List<OrderClientDto>();

Nhb 远非直观和方便。在 EF 中编写相同的查询要容易得多。