The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.

 _investmentRepository.Table.Where(t => t.CustomerId == customerId && t.InvestmentStatus == tempStatus).Sum(t =>t.Amount);

查询结果存在NULL值,在尝试将它转换成System.Int32时出了错,解决方法如下

_investmentRepository.Table.Where(t => t.CustomerId == customerId && t.InvestmentStatus == tempStatus).Sum(t => (decimal?)t.Amount) ?? 0;

posted @ 2016-10-18 13:09  z_hj  阅读(1912)  评论(0编辑  收藏  举报