Created
April 3, 2019 14:11
-
-
Save Beelzenef/56e04cc86d1192913e4ea60bf7120552 to your computer and use it in GitHub Desktop.
A left join combined with group by combined with sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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