2
我正在LINQ中寫入一個lambda,以便從結果列表中獲取pivoted數據。爲了獲取pivoting列,我正在設置一個where condion來獲取值。這裏的問題是獲取默認值if在哪裏condtion失敗。我不想要列,如果where條件失敗。請幫助我。使用lambda表達式在LINQ中旋轉
var query = dataList
.GroupBy(c => c.IpAddress)
.Select(g => new
{
IPAddress = g.Key,
AssetType = g.ElementAtOrDefault(0).AssetTypeName,
AssetName = g.ElementAtOrDefault(0).AssetName,
//if where condition fails i dont need this column.
//also am giving c.DsName == "Active Calls" ,how to achieve tis dynamically
**ActiveCalls = g.Where(c => c.DsName == "Active Calls").Sum(c => c.CurrentValue),**
**HoldCalls = g.Where(c => c.DsName == "Hold Calls").Sum(c => c.CurrentValue),**
**CPU = g.Where(c => c.DsName == "CPU").Sum(c => c.CurrentValue),**
});
有沒有必要添加一個答案來編輯您的問題... – jeroenh 2010-08-04 11:23:48