using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { public class Plan { public string ProjectInfoId { get; set; } public string CommandInfoId { get; set; } public int value { get; set; } } class Program { static void Main(string[] args) { List<Plan> listPlan = new List<Plan>() { new Plan{ProjectInfoId="01", CommandInfoId="01001", value=0}, new Plan{ProjectInfoId="01", CommandInfoId="01001", value=0}, new Plan{ProjectInfoId="01", CommandInfoId="01002", value=0}, new Plan{ProjectInfoId="02", CommandInfoId="02001", value=0}, new Plan{ProjectInfoId="02", CommandInfoId="02002", value=1}, new Plan{ProjectInfoId="02", CommandInfoId="02002", value=1}, }; var PlanGroups = from p in listPlan group p by new { p.ProjectInfoId, p.CommandInfoId } into g let condition = g.Sum<Plan>(t => t.value) where condition > 0 select new { g.Key, NumProducts = condition }; foreach (var group in PlanGroups) { Console.WriteLine(string.Format("{0},{1}:{2}", group.Key.ProjectInfoId.ToString(), group.Key.CommandInfoId.ToString(), group.NumProducts)); } } } }