Skip to content

Instantly share code, notes, and snippets.

@phatty
Last active December 15, 2015 11:49
Show Gist options
  • Save phatty/5255849 to your computer and use it in GitHub Desktop.
Save phatty/5255849 to your computer and use it in GitHub Desktop.
var Records = context.Customers.Join(context.TransactionExchangeMoneys
, x => x.Cust_ID
, y => y.PayBy
, (x, y) => new { x, y })
.Join(context.Products
, t=> t.y.ProductID
, p => p.ProductID
, (t,p) => new {t,p})
.GroupBy(r => new { r.t.x.Cust_ID,r.t.x.UserNames ,r.t.x.EmailAddress_First,r.t.x.ShopName})
.Select(g => new UserAndMoneyPaid
{
Username = g.Key.UserNames,
Email = g.Key.EmailAddress_First,
ShopName = g.Key.ShopName,
TotalMoneyCollect = g.Sum(a=>a.p.MoneyReturnShop),
TotalMoneyPaid = g.Where(a=>a.t.y.ReturnMoney != null).Sum(a=>a.t.y.ReturnMoney)
})
.OrderBy(o=>o.Username);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment