2016-05-17 34 views
1

我想允許g.CustomerBillId除了現有的邏輯之外還可以刪除空值。嘗試向LINQ語句添加左連接

var previous = from g in FindAllCustomerPayments(obj.CustomerId) 
       join a in custPay        
       on g.CustomerBillId equals a.CustomerBillId 
       where System.Data.Entity.DbFunctions.TruncateTime(g.TransactionDateTime) <= previousBill.EffectiveDate 
       group g by new 
       { 
        CustomerId = g.CustomerId 

       } into p 
       select new 
       { 
        p.Key, 
        previousBalance = p.Sum(n => n.Credit) - p.Sum(n => n.Debit) 
       }; 
+0

好了,這是什麼,你已經得到了代碼給你? (以及爲什麼你要爲單個客戶ID屬性創建一個新的匿名類型?只需將g.CustomerId中的g組合到p中就行了) –

回答

0

你可以只

from a in custPay.where(cust => cust.CustomerBillId = g.CustomerBillId).DefaultIfEmpty()