public class Foo
{
public Int32 ProjectNumber;
public String ItemNumber;
public String InventLocation;
public Int32 Qty;
}
void Main()
{
List<Foo> foos = new List<Foo>(new[]{
new Foo { ProjectNumber = 1, ItemNumber = "a", InventLocation = "Main", Qty = 3 },
new Foo { ProjectNumber = 1, ItemNumber = "a", InventLocation = "Main", Qty = 3 },
new Foo { ProjectNumber = 1, ItemNumber = "a", InventLocation = "Sub", Qty = 2 },
new Foo { ProjectNumber = 1, ItemNumber = "a", InventLocation = "Sub", Qty = 1 },
new Foo { ProjectNumber = 1, ItemNumber = "a", InventLocation = "Sub2", Qty = 5 }
});
var foo = from f in foos
group f by new { f.ProjectNumber, f.ItemNumber } into fGroup
select new {
ProjectNumber = fGroup.Key.ProjectNumber,
ItemNumber = fGroup.Key.ItemNumber,
QtyMain = fGroup.Where (g => g.InventLocation == "Main").Sum (g => g.Qty),
Rest = fGroup.Where (g => g.InventLocation != "Main").Sum (g => g.Qty)
};
foo.Dump();
}
[? LINQ to SQL은의 합계와 그룹으로]
IEnumerable<> (1 item)
ProjectNumber ItemNumber QtyMain Rest
1 a 6 8
이것은의 중복 (http://stackoverflow.com/questions/216513/sum-and-group -by-in-linq-to-sql) –
나는 그럴 수 없다고 생각하지만, 아마 VB에서는 잘 모른다. –