Skip to content

Instantly share code, notes, and snippets.

@Beelzenef
Created April 3, 2019 14:11
Show Gist options
  • Save Beelzenef/56e04cc86d1192913e4ea60bf7120552 to your computer and use it in GitHub Desktop.
Save Beelzenef/56e04cc86d1192913e4ea60bf7120552 to your computer and use it in GitHub Desktop.
A left join combined with group by combined with sum
public async Task<List<Result>> GetDistributionEvolution(List<Guid> listOfElements, int status)
{
var results = await (from firsts in _dbContext.FirstList
join seconds in _dbContext.SecondList on firsts.Id equals seconds.ForeginKey
into scs
from scsResult in scs.DefaultIfEmpty()
where scsResult.StatusId == stateId &&
listOfElements.Contains(scsResult.ElementKey)
group scsResult by firsts.Year into yearGroup
select new Result
{
Year = yearGroup.Key,
Amounts = yearGroup.Sum(g => g.GrossAmount)
}).ToListAsync();
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment