0
我有這個NHibernate的性判據的正常工作NHibernate的Expression.In拋出異常
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"];
任何想法,爲什麼會發生,由way 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
是的,我得到了我有一個異常,這給了我的想法,我的錯誤來自何處,UniqueResult給我的問題,因爲我返回一個空數據。 +1 – Raymund 2012-04-22 20:02:24