Skip to content

Instantly share code, notes, and snippets.

@ayende

ayende/index.cs Secret

Created July 7, 2022 12:13
// maps
from u in docs.Users
select new {
u.Id,
u.Name,
Amount = 0
}
from c in docs.Charges
select new {
Id = c.User,
Amount = -c.Amount,
Name = default(string)
}
from c in docs.Credits
select new {
Id = c.User,
c.Amount,
Name = default(string)
}
// reduce
from r in results
group r by r.Id into g
let user = g.FirstOrDefault(x=>x.Name != null)
select new
{
user.Name,
user.Id,
Amount = g.Sum(x=>x.Amount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment