我使用WCF RIA服务(Silverlight应用程序)下面的代码:解决拉姆达铸造错误
public partial class BillingWaterDomainService : LinqToEntitiesDomainService<BilingWaterEntities>
{
public ObservableCollection<PaymentSummary> GetPaymentSummary(long requestId)
{
var paymentSummaries = new ObservableCollection<PaymentSummary>();
var result = GetRequestCostDetailsByRequestId(requestId);
foreach (var requestCostDetail in result.Where(r=>r.BranchCostId.HasValue))
{
if (requestCostDetail.Debtor.HasValue)
{
RequestCostDetail detail = requestCostDetail;
long? costCustomerPrice = 0;
costCustomerPrice =
result.Where(
r => r.CostCustomerDetail.CostCustomerType.CostTypeId == detail.BranchCostDetail.CostType && r.Creditor.HasValue).
Sum(r => r.Creditor != null ? r.Creditor.Value : 0);
paymentSummaries.Add(new PaymentSummary()
{
PaymentTitle = requestCostDetail.BranchCostDetail.CostType1.CostTitle,
Price = requestCostDetail.Debtor.Value-(costCustomerPrice.HasValue ? costCustomerPrice.Value:0)
});
}
}
return paymentSummaries;
}
}
当我尝试执行该代码,我有以下错误:
Invoke Operation 'GetPaymentSummary' failed.The cast to value type 'Int64' failed because the materialized value is null.Either the result type 's generic parameter or the query must use a nullable type
此错误在下面的代码行:
costCustomerPrice =result.Where(
r => r.CostCustomerDetail.CostCustomerType.CostTypeId == detail.BranchCostDetail.CostType && r.Creditor.HasValue).
Sum(r => r.Creditor != null ? r.Creditor.Value : 0);
这一段代码:
r => r.CostCustomerDetail.CostCustomerType.CostTypeId
我该如何解决这个问题?
“GetPaymentSummary”在哪里调用? – 2012-03-06 17:28:48
哪条线路故障?请显示完整的堆栈跟踪。 – 2012-03-06 17:30:05
我在客户端Silverlight应用程序中调用了'GetPaymentSummary'。 – 2012-03-06 17:33:50