我需要为实体构建查询以获取记录,包括:
AssetWeapon
,PersonOut
IsIn = True
,IsIn = False
,StartTime
月份的名称,记录应按AssetWeapon
alt text http://www.freeimagehosting.net/uploads/4fee01b48c.png
答案 0 :(得分:0)
答案 1 :(得分:0)
这是我最终得到的:
var query = from ta in db.Transactions_Assets.Include("Transaction")
let items = new
{
Weapon = ta.AssetWeapon,
Month = ta.Transaction.StartTime.Value.Month,
IsIn = ta.IsIn
}
group items by items.Weapon into g
select new {
Weapon = g.Key,
MonthlyFlow = from m in g
group m by m.Month into mg
select new { Month = mg.Key,
Ins = mg.Count( x => x.IsIn == true),
outs = mg.Count(x => x.IsIn == false)
}
};