8,497
社区成员
发帖
与我相关
我的任务
分享
var result = from u in entity.table
group u by new { u.login, u.Goods, u.Date } into temp
select new
{
login = temp.Key.login,
Goods = temp.Key.Goods,
TotalPrice = temp.Sum(c => c.Price),
TotalQty = temp.Sum(c => c.Qty),
BQty = temp.Where(c => c.Key == "B").Sum(c => c.Qty),
SQty = temp.Where(c => c.Key == "S").Sum(c => c.Qty),
Date = temp.FirstOrDefault().Date
};
2:如下
using (NorthwindEntities entity = new NorthwindEntities())
{
var result = from u in entity.table
group u by new { u.login, u.Goods, u.Date } into temp
select new
{
login = temp.Key.login,
Goods = temp.Key.Goods,
TotalPrice = temp.Sum(c => c.Price),
TotalQty = temp.Sum(c => c.Qty),
BQty = temp.GroupBy(c => c.Bos).Where(c => c.Key == "B").Sum(c => c.Qty),
SQty = temp.GroupBy(c => c.Bos).Where(c => c.Key == "S").Sum(c => c.Qty),
Date = temp.FirstOrDefault().Date
};
}
var result = from u in entity.table
group u by new { u.login, u.Goods, u.Date } into temp
select new
{
login = temp.Key.login,
Goods = temp.Key.Goods,
TotalPrice = temp.Sum(c => c.Price),
TotalQty = temp.Sum(c => c.Qty),
BQty = temp.Where(c => c.Key == "B").Count(),
SQty = temp.Where(c => c.Key == "S").Count(),
Date = temp.FirstOrDefault().Date
};
using (NorthwindEntities entity = new NorthwindEntities())
{
var result = from u in entity.table
group u by new { u.login, u.Goods, u.Date } into temp
select new
{
login = temp.Key.login,
Goods = temp.Key.Goods,
TotalPrice = temp.Sum(c => c.Price),
TotalQty = temp.Sum(c => c.Qty),
BQty = temp.GroupBy(c => c.Bos).Where(c => c.Key == "B").Count(),
SQty = temp.GroupBy(c => c.Bos).Where(c => c.Key == "S").Count(),
Date = temp.FirstOrDefault().Date
};
}