我使用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