以下LINQ中有一些
在下面的查询中,
Convert.ToInt32
方法。但它不起作用。参考互联网,应该使用int.Parse
而不是convert。仍然会出错。请指导我如何做。在下面的查询中,
tody
的数据类型是DateTime
。var ds = (from a in dbSetInvHeader
join b in dbSetCustomer on a.BusinessEntityID equals b.Id
join c in dbSetFinancialInfo on b.Id equals c.Id
where (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount) > 0
&& DbFunctions.AddDays(a.InvoiceDate, Convert.ToInt32(c.CreditPeriod)) >= tody
select new OverDueInvoices
{
CustomerName = b.Name,
InvoiceNo = a.InvoiceNo,
InvoiceAmount = a.TotalAmount - a.ApplyToInvoiceCreditAmount,
DueAmount = (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount),
CreditAmount = a.ApplyToInvoiceCreditAmount,
NoOfDays = Convert.ToInt32(DbFunctions.DiffDays(tody, a.InvoiceDate))
}).ToList();
更新:
以上的LINQ代码使用了Entity Framework,会导致错误:
当使用Convert.ToInt32
时:
"LINQ to Entities不识别方法'Int32 ToInt32(System.Decimal)',并且无法将此方法转换为存储表达式。"
当使用int.Parse
时:
"LINQ to Entities不识别方法'Int32 Parse(System.String)',并且无法将此方法转换为存储表达式。"
DbFunctions.DiffDays
已经返回了一个Nullable<int>
。你对Convert.ToInt32
方法有什么期望? - grek40