Having podmiotów NHibernate:LINQ do NHibernate: suma kwot
Company
, Invoice
i InvoiceLine
który ma właściwość dziesiętną Price
.
A Company
ma kolekcję typu Invoice
, a Invoice
ma kolekcję typu InvoiceLine
.
W jaki sposób mogę uzyskać sumę wszystkich cen, które należą do wierszy faktury, które należą do faktur określonej firmy określonej przez id?
Próbowałem napisać kwerendę tak:
session
.Query<InvoiceLine>()
.Where(invoiceLine => invoiceLine.Invoice.Company.Id == companyId)
.Sum(invoiceLine => invoiceLine.Price);
ale zgłasza wyjątek:
NHibernate.Exceptions.GenericADOException
"Could not execute query[SQL: SQL not available]"
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
at NHibernate.Impl.ExpressionQueryImpl.List()
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
wewnętrzny wyjątek:
System.ArgumentNullException
"Value cannot be null.\r\nParameter name: item"
at System.ThrowHelper.IfNullAndNullsAreIllegalThenThrow[T](Object value, ExceptionArgument argName)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at NHibernate.Util.ArrayHelper.<>c__DisplayClass2.<AddAll>b__0()
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
Może to mieć coś wspólnego z podsumowując puste kolekcje, ale nie jestem pewien, jak to naprawić.
to prawie rozwiązanie, należy zmienić go na '.Sum (invoiceLine => (dziesiętny?) InvoiceLine.Price) ?? 0', więc mogę przegłosować i zaakceptować. –