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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM