# LINQ GROUPBY和带有Dapper的SUM可以实现吗？

``````    DailyLoanCalculation table
Day    Account No   Loan     interest Amount Per day
1         12345     3000       150
1         23456     1000       50
1         43567     2500       125
2         12345     3000       150
2         23456     1000       50
2         43567     2500       125

Total-Interest Table
Day Account No  Loan   Total Interest  Total
30  12345       3000    300            3300
30  23456       1000    100            1100
30  43567       2500    250            2750

``````

`````` //Calculate the EndOfMonthDailyInterestCalculation
public void EndOfMonthDailyInterestCalculation()
{
IEnumerable<DailyInterest> loans = null;

using (var conn = new SqlConnection(ConnectionString))
{
conn.Open();

loans = conn.Query<DailyInterest>("Select * from DailyInterest where BackgroundMonthly is Null");
if (loans.Count() == 0)
{
return;
}

var TotalEachLoanInterest = loans.GroupBy(x => x.LoanAccountNo).Select(g =>g.Sum(x=>x.AmountPerDay));

**//I can go further at this point**

if (TotalEachLoanInterest.Count() == 0)
{
return;
}
else
{
foreach (var loan in loans)
{

var SumOfInteretForTheMonth = loan.

var markDailyAsCalculated = new
{
amountPerday = loan.AmountPerDay
};

}
}
}
}
``````