Linq to Entities 中的左外连接 (asp.net vb)

Left outer join in Linq to Entities (asp.net vb)

我被这个问题困扰太久了,我认为这只是我的经验不足。我研究过许多类似的文章,但 none 似乎在我将其应用于我的情况时起作用。

我正在使用 linq to entities with EF6.I 有两个简单的 tables 'LoanRepayment' 和 'LoanReceipt'。他们与从 LoanRepayment.LoanPaymentId 到 LoanReceipt.LoanPaymentId 的外国有联系。有 48 个固定贷款付款,其中 4 个有收据。我只是想创建一个包含 48 行的 table,其中包含来自 LoanRepayment table 的所有 48 行和任何存在的收据数据(即 4)。尚未支付的贷款旁边的其余单元格应为空白。

Dim queryLoanRepayments = (From lp In proxifundContext.LoanRepayments Group 
Join lr In proxifundContext.LoanReceipts On lr.LoanPaymentId Equals
lp.LoanPaymentId Into paymentlist = Group From lr In 
paymentlist.DefaultIfEmpty() Select lp.InstallmentNo, lp.InstallmentAmount, 
lp.Penalty, lp.PaymentDate, If(lr.ReceiptDate Is Nothing, String.Empty, 
lr.ReceiptDate), If(lr.Amount Is Nothing, String.Empty, lr.Amount)).ToList()

当我 运行 时,智能感知上面的查询用消息 "Range variable name can be inferred only from a simple or qualified name with no arguments".

在两个 If 语句下划线

我做错了什么?

您应该自己给计算出的属性命名,因为 VB 无法推断它们(就像从简单的 属性 中推断的那样):

...
Select lp.InstallmentNo, 
       lp.InstallmentAmount, 
       lp.Penalty,
       lp.PaymentDate,
       ReceiptDate = If(lr.ReceiptDate Is Nothing, String.Empty, 
       lr.ReceiptDate),
       Amount = If(lr.Amount Is Nothing, String.Empty, lr.Amount)

谢谢格特·阿诺德。你给我指明了正确的方向。实际有效的声明是:

Dim queryLoanRepayments = (From lp In proxifundContext.LoanRepayments Group 
Join lr In proxifundContext.LoanReceipts On lr.LoanPaymentId Equals 
lp.LoanPaymentId Into paymentlist = Group From lr In 
paymentlist.DefaultIfEmpty() 
Select lp.LoanApplicationId, 
       lp.InstallmentNo, 
       lp.InstallmentAmount, 
       lp.Penalty, 
       lp.PaymentDate, 
       ReceiptDate = If(lr.ReceiptDate = Nothing, String.Empty, CStr(lr.ReceiptDate)), 
       Amount = If(lr.Amount = Nothing, String.Empty, CStr(lr.Amount))).ToList()