tags:

views:

65

answers:

1

I am writing a lambda in linq for getting the pivoted data from the resulting list.For getting the pivoting columns am setting a where condion to get the value.the problem here is am getting default value if the where condtion fails.I dont want the column if the where condition fails.Kindly help me out.

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),**
    });
A: 

After making alignment proper

I am writing a lambda in linq for getting the pivoted data from the resulting list.For getting the pivoting columns am setting a where condion to get the value.the problem here is am getting default value if the where condtion fails.I dont want the column if the where condition fails.Kindly help me out.Below is the query.

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),

          });
judes