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