1

在 Nhibernate 3.2 上,我遇到了 Linq 查询问题:

        var temp = Session.Query<RequestForQuotation>().OrderByDescending(o => o.DateIssued).ToList();
        var temp2 = Session.Query<RequestForQuotation>().OrderByDescending(o => o.DateIssued).SelectMany(o => o.RequestForQuotationItems).ToList();
        var temp3 = Session.Query<RequestForQuotation>().OrderByDescending(o => o.DateIssued).SelectMany(o => o.RequestForQuotationItems).Select(o => o.SupplierProduct).ToList();

temp3 抛出异常

NHibernate.QueryException:无法解析属性:DateIssued of:XXXX.Domain.Entities.RequestForQuotationItem

显然 DateIssued 是 RequestForQuotation 的属性/列而不是 RequestForQuotationItem

这是 Nhibernate Query 的一个已知问题还是我的想法有问题?有解决方法吗?

4

2 回答 2

1

可能的解决方法似乎是这样,但我不确定:

Session.Query<RequestForQuotation>().SelectMany(o => o.RequestForQuotationItems, (rfq, rfqi) => new { rfq, rfqi }).OrderByDescending(o => o.rfq.DateIssued).Select(o => o.rfqi.SupplierProduct)
于 2012-06-07T11:12:40.057 回答
0

可能的解决方法(没有 SelectMany)

Session.Query<RequestForQuotationItem>()
  .OrderByDescending(i => i.RequestForQuotation.DateIssued)
  .Select(i => i.SupplierProduct)
  .ToList(); 
于 2012-06-07T13:25:44.677 回答