0

私はこのnHibernateCriteraを持っています。

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クエリです

SELECT SUM(InvoiceGross) AS total
FROM  Transactions
WHERE (AccountID = @accountId) (statusTypeID IN (1,2,3,4))
GROUP BY AccountID
4

1 に答える 1