Availability of NHibernate objects:
Company , Invoice and InvoiceLine , which has the decimal property Price .
A Company has an Invoice type set, and Invoice has an InvoiceLine type InvoiceLine .
How can I get the sum of all prices related to lines of accounts that belong to accounts of a certain company indicated by identifier?
I tried to write a query as follows:
session .Query<InvoiceLine>() .Where(invoiceLine => invoiceLine.Invoice.Company.Id == companyId) .Sum(invoiceLine => invoiceLine.Price);
but it throws an exception:
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)
internal exception:
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)
This may have something to do with summing up empty collections, but I'm not sure how to fix this.