我正在計算我的兩列的餘額。我嘗試了很多方法,但沒有運氣。計算Linq中的運行總數
如:
我希望得到這樣的結果:
借記 信用 餘額
===== = ===== =======
125.00 0.00 125.00
236.00 0.00 361.00
0.00 100.00 261.00
我的代碼
var filteredSales = (from av in db.AccountVouchers
join l in db.Ledgers on new {LedgerID = (Int32) av.LedgerID} equals new {LedgerID = l.LedgerID}
join sm in db.SalesMasters on av.VoucherNo equals sm.BillNo.ToString()
where (av.VoucherDate >= FromDate && av.VoucherDate <= ToDate && av.LedgerID == LedgerID)
group new {av, l, sm} by new
{
av.VoucherDate,
l.LedgerName,
av.VoucherType,
av.VoucherNo,
sm.REFNO,
av.Debit,
av.Credit,
av.Narration
}
into g
select new
{
g.Key.VoucherDate,
g.Key.LedgerName,
g.Key.VoucherType,
VoucherNo = (g.Key.VoucherType != "SALES" ? g.Key.REFNO : g.Key.VoucherNo),
//g.Key.VoucherNo,
g.Key.Debit,
g.Key.Credit,
g.Key.Narration,
dSum = g.Sum(s => s.av.Debit),
//Balance=g.Key.Debit-g.Key.Credit,
// TBal = int.Parse(TBal) + (g.Key.Debit != 0 ? TBal + g.Key.Debit : TBal - g.Key.Credit))
}).ToList();
你是什麼意思大約'Caculate balance'?你只是展示你想要的結果 – 2014-09-04 06:44:28
你想做什麼?運行總數?或者你是否需要更新記錄? – flindeberg 2014-09-04 07:14:26