符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
本篇内容主要讲解“强制转换为值类型“System.Double”失败的原因”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“强制转换为值类型“System.Double”失败的原因”吧!
目前成都创新互联公司已为上1000家的企业提供了网站建设、域名、虚拟主机、网站托管、服务器托管、企业网站设计、松原网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
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.
主要原因是没有适合查询条件的行 去计算,
所以改成以下写法就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); }
到此,相信大家对“强制转换为值类型“System.Double”失败的原因”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!