我需要建立一個查詢到實體獲得的記錄,包括:LINQ到實體查詢(1對多)
AssetWeapon
,PersonOut
- 許多與
IsIn = True
記錄, - 記錄數
IsIn = False
, - 本月的名稱
StartTime
,
記錄應當由AssetWeapon
alt text http://www.freeimagehosting.net/uploads/4fee01b48c.png
我需要建立一個查詢到實體獲得的記錄,包括:LINQ到實體查詢(1對多)
AssetWeapon
,PersonOut
IsIn = True
記錄,IsIn = False
,StartTime
,記錄應當由AssetWeapon
alt text http://www.freeimagehosting.net/uploads/4fee01b48c.png
謝謝!它有幫助 – Agzam 2010-05-18 16:27:18
在這裏我得到了什麼最後:
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)
}
};
我只是不知道如何建立一個查詢。在db.Transactions_Assets.Include(「交易」)) – Agzam 2010-05-18 14:53:56
好,我得到了這一點,並卡住了... VAR的查詢=從TA 選擇新 { ;我的愚蠢頭腦不正常得到這個工作Weapon = ta.AssetWeapon, Month = ta.Transaction.StartTime.Value.Month, In = ta.IsIn? 1:0, Out = ta.IsIn? 0:1 }; – Agzam 2010-05-18 15:33:46