Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Reasons for failure to cast to value type "System.Double"

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the reason why casting to value type"System.Double"fails". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "the reason why casting to value type"System.Double"fails"!

foreach (var item in entityList) { ChannelReportDto channelReportDto = new ChannelReportDto(); channelReportDto.Id = item.Id; channelReportDto.YueziCenterId = item.YueziCenterId; channelReportDto.YueziCenterName = item.YueziCenterName; channelReportDto.ChannelName = item.ChannelName; channelReportDto.SumProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsDeleted == false).Select(s => s.SumProfitAmount).Sum(); channelReportDto.SettleProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsSettlement == true).Select(s => s.SumProfitAmount).Sum(); channelReportDto.NoSettleProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsSettlement == false).Select(s => s.SumProfitAmount).Sum(); list.Add(channelReportDto); }

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

The main reason is that there are no rows suitable for query conditions to calculate,

So change it to OK

foreach (var item in entityList) { ChannelReportDto channelReportDto = new ChannelReportDto(); channelReportDto.Id = item.Id; channelReportDto.YueziCenterId = item.YueziCenterId; channelReportDto.YueziCenterName = item.YueziCenterName; channelReportDto.ChannelName = item.ChannelName; channelReportDto.SumProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsDeleted == false).Sum(s =>(double?) s.SumProfitAmount)?? 0.00; channelReportDto.SettleProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsSettlement == true).Sum(s => (double?) s.SumProfitAmount) ?? 0.00; channelReportDto.NoSettleProfitAmount = OrderServiceProjectresult.Where(w => w.ChannelId == item.Id && w.IsSettlement == false).Sum(s => (double?) s.SumProfitAmount) ?? 0.00; list.Add(channelReportDto); } At this point, I believe that everyone has a deeper understanding of the "reason why the cast to the value type"System.Double"fails". Let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report