Last active
August 16, 2020 09:36
-
-
Save ayende/94f677b850f97deb021540f358142a22 to your computer and use it in GitHub Desktop.
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
AddMap<Company>(companies => from company in companies | |
select new | |
{ | |
CompanyName = company.CompanyName, | |
UserCount = 0 | |
CompanyId = company.Id | |
}); | |
AddMap<User>(users => from user in users | |
from companyId in user.Companies | |
select new | |
{ | |
CompanyName = default(string), | |
UserCount = 1, | |
CompanyId = companyId | |
}); | |
Reduce = results => | |
from result in results | |
group result by result.CompanyId | |
into g | |
select new | |
{ | |
CompanyId = g.Key, | |
CompanyName = g.First().CompanyName, | |
UserCount = g.Sum(dto => dto.UserCount) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment