using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program
{
static void Main(string[] args)
{
// some sample data
List<AggregateGrouping> lstgrpelements = new List<AggregateGrouping>();
lstgrpelements.Add(new AggregateGrouping{ Name = "Mike", CITY= "Tallahassee", STATE= "FL", value=-3.12M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Mike", CITY= "Tallahassee", STATE= "FL", value=6.57M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Steve", CITY= "Tallahassee", STATE= "FL", value=-7.34M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Steve", CITY= "Tallahassee", STATE= "FL", value=54.64M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Steve", CITY= "Orlando", STATE= "FL", value=-10.93M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Steve", CITY= "Orlando", STATE= "FL", value=235.09M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Mike", CITY= "Orlando", STATE= "NY", value=429.34M });
lstgrpelements.Add(new AggregateGrouping{ Name = "Mike", CITY= "Orlando", STATE= "NY", value=-67.12M });
// Converts to list to iEnumrable.
IEnumerable<AggregateGrouping> enumgrpelements = lstgrpelements;
}
}
Public Class AggregateGrouping
{
public string Name { get; set; }
public string CITY{ get; set; }
public string STATE{ get; set; }
public decimal value{ get; set; }
}
如何使用Dynamic Linq将IEnumerable转换为groupby(CITY AND STATE)动态数据聚合(在Values上)。 CITY和STATE列是示例,但可以在运行时对多个列进行动态分组。我希望输出为值字段上的聚合。
谢谢,Ashutosh。