Kaido
Kaido

Reputation: 3951

NHibernate .OrderBy.SelectMany.Select

On Nhibernate 3.2 I'm having trouble with a Linq Query:

        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 throws exception

NHibernate.QueryException : could not resolve property: DateIssued of: XXXX.Domain.Entities.RequestForQuotationItem

obviously DateIssued is a property/column of RequestForQuotation not RequestForQuotationItem

Is this a known issue with Nhibernate Query or something wrong with my thinking? Is there a workaround?

Upvotes: 1

Views: 833

Answers (2)

Amy B
Amy B

Reputation: 110111

Possible workaround (have no SelectMany)

Session.Query<RequestForQuotationItem>()
  .OrderByDescending(i => i.RequestForQuotation.DateIssued)
  .Select(i => i.SupplierProduct)
  .ToList(); 

Upvotes: 0

Kaido
Kaido

Reputation: 3951

Possible workaround seems to be this, but I'm not sure about it:

Session.Query<RequestForQuotation>().SelectMany(o => o.RequestForQuotationItems, (rfq, rfqi) => new { rfq, rfqi }).OrderByDescending(o => o.rfq.DateIssued).Select(o => o.rfqi.SupplierProduct)

Upvotes: 1

Related Questions