[英]LINQ to entities query (1 to many)
我需要对实体建立查询以获取记录,包括:
AssetWeapon
, PersonOut
IsIn = True
的记录数 IsIn = False
的记录数, StartTime
月份的名称, 记录应按AssetWeapon
分组
这是我终于得到的:
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)
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.