ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,187 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have Some Data below Image. How Can do this Using LINQ Query.
Thanks for posting your question in the Microsoft Q&A forum.
You can group the data by month and year and then calculate the sum of each group. Here's how you can do it:
var result = from credit in credits
group credit by new
{
Month = credit.Date.Month,
Year = credit.Date.Year
} into creditGroup
join debit in debits on new
{
Month = creditGroup.Key.Month,
Year = creditGroup.Key.Year
}
equals new
{
Month = debit.Date.Month,
Year = debit.Date.Year
} into joinedGroup
from debit in joinedGroup.DefaultIfEmpty()
select new
{
Month = creditGroup.Key.Month,
Year = creditGroup.Key.Year,
Credit1 = creditGroup.Sum(c => c.Credit1),
Credit2 = creditGroup.Sum(c => c.Credit2),
Debit = debit != null ? debit.DebitAmount : 0,
Result = (creditGroup.Sum(c => c.Credit1) + creditGroup.Sum(c => c.Credit2)) - (debit != null ? debit.DebitAmount : 0)
};
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful