我有这个工作正常的 nHibernate Critera
var amount = (decimal)Session.CreateCriteria<Transaction>()
.Add(Expression.Eq("Account.Id", accountId))
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("Account.Id"))
.Add(Projections.Sum("InvoiceGross"), "total"))
.SetMaxResults(1)
.SetResultTransformer(Transformers.AliasToEntityMap)
.UniqueResult<IDictionary>()["total"];
但是当我开始Expression.In
像这样添加时
var amount = (decimal)Session.CreateCriteria<Transaction>()
.Add(Expression.Eq("Account.Id", accountId))
.Add(Expression.In("StatusType.Id", statusTypes))
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("Account.Id"))
.Add(Projections.Sum("InvoiceGross"), "total"))
.SetMaxResults(1)
.SetResultTransformer(Transformers.AliasToEntityMap)
.UniqueResult<IDictionary>()["total"];
任何想法为什么会发生,顺便说一下statusTypes
是一种int[]
类型
它开始抛出异常"Object reference not set to an instance of an object."
这是我想要实现的 SQL Query
SELECT SUM(InvoiceGross) AS total
FROM Transactions
WHERE (AccountID = @accountId) (statusTypeID IN (1,2,3,4))
GROUP BY AccountID