Skip to main content

GroupBy - Simple

This sample uses group by to partition Products by CategoryID.

Public Sub LinqToSqlGroupBy01()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into Group _
            Select Group

    ObjectDumper.Write(q, 1)
End Sub


Result:
  ...
    ProductID=1     ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=2     ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=24    ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=34    ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=35    ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=38    ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=39    ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=43    ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=67    ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=70    ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=75    ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=76    ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=3     ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=4     ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=5     ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=6     ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=8     ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=15    ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=44    ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=61    ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=63    ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=65    ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=66    ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=77    ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=16    ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=19    ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=20    ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=21    ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=25    ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=26    ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=27    ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=47    ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=48    ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=49    ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=50    ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=62    ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=68    ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=11    ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=12    ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=31    ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=32    ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=33    ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=59    ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=60    ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=69    ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=71    ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=72    ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=22    ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=23    ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=42    ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=52    ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=56    ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=57    ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=64    ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=9     ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=17    ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=29    ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=53    ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=54    ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=55    ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=7     ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=14    ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=28    ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=51    ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=74    ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=10    ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=13    ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=18    ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=30    ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=36    ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=37    ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=40    ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=41    ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=45    ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=46    ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=58    ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=73    ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }


GroupBy - Max

This sample uses group by and Max to find the maximum unit price for each CategoryID.

Public Sub LinqToSqlGroupBy02()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into g = Group _
            Select New With {g, .MaxPrice = g.Max(Function(p) p.UnitPrice)}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  g=...   MaxPrice=778.7700
    g: ProductID=1  ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=2  ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=24         ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=34         ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=35         ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=38         ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=39         ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=43         ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=67         ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=70         ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=75         ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=76         ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=44.9000
    g: ProductID=3  ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=4  ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=5  ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=6  ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=8  ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=15         ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=44         ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=61         ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=63         ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=65         ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=66         ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=77         ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=82.0000
    g: ProductID=16         ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=19         ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=20         ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=21         ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=25         ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=26         ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=27         ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=47         ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=48         ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=49         ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=50         ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=62         ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=68         ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=56.0000
    g: ProductID=11         ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=12         ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=31         ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=32         ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=33         ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=59         ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=60         ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=69         ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=71         ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=72         ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=39.0000
    g: ProductID=22         ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=23         ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=42         ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=52         ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=56         ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=57         ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=64         ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=124.7900
    g: ProductID=9  ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=17         ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=29         ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=53         ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=54         ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=55         ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=54.0000
    g: ProductID=7  ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=14         ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=28         ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=51         ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=74         ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MaxPrice=63.5000
    g: ProductID=10         ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=13         ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=18         ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=30         ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=36         ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=37         ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=40         ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=41         ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=45         ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=46         ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=58         ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=73         ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }


GroupBy - Min

This sample uses group by and Min to find the minimum unit price for each CategoryID.

Public Sub LinqToSqlGroupBy03()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into g = Group _
            Select New With {g, .MinPrice = g.Min(Function(p) p.UnitPrice)}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  g=...   MinPrice=5.5000
    g: ProductID=1  ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=2  ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=24         ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=34         ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=35         ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=38         ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=39         ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=43         ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=67         ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=70         ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=75         ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=76         ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=11.0000
    g: ProductID=3  ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=4  ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=5  ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=6  ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=8  ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=15         ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=44         ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=61         ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=63         ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=65         ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=66         ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=77         ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=10.2000
    g: ProductID=16         ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=19         ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=20         ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=21         ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=25         ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=26         ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=27         ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=47         ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=48         ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=49         ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=50         ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=62         ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=68         ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=3.5000
    g: ProductID=11         ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=12         ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=31         ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=32         ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=33         ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=59         ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=60         ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=69         ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=71         ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=72         ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=8.0000
    g: ProductID=22         ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=23         ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=42         ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=52         ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=56         ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=57         ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=64         ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=8.4500
    g: ProductID=9  ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=17         ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=29         ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=53         ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=54         ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=55         ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=11.0000
    g: ProductID=7  ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=14         ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=28         ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=51         ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=74         ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   MinPrice=7.0000
    g: ProductID=10         ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=13         ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=18         ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=30         ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=36         ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=37         ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=40         ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=41         ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=45         ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=46         ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=58         ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=73         ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }


GroupBy - Average

This sample uses group by and Average to find the average UnitPrice for each CategoryID.

Public Sub LinqToSqlGroupBy04()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into Group _
            Select New With {Group, .AveragePrice = Group.Average(Function(p) p.UnitPrice)}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  AveragePrice=102.2933   Group=...
    Group: ProductID=1      ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=2      ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=24     ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=34     ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=35     ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=38     ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=39     ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=43     ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=67     ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=70     ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=75     ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=76     ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=24.0625    Group=...
    Group: ProductID=3      ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=4      ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=5      ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=6      ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=8      ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=15     ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=44     ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=61     ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=63     ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=65     ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=66     ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=77     ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=26.1600    Group=...
    Group: ProductID=16     ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=19     ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=20     ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=21     ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=25     ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=26     ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=27     ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=47     ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=48     ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=49     ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=50     ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=62     ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=68     ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=29.7300    Group=...
    Group: ProductID=11     ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=12     ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=31     ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=32     ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=33     ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=59     ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=60     ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=69     ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=71     ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=72     ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=21.2500    Group=...
    Group: ProductID=22     ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=23     ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=42     ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=52     ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=56     ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=57     ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=64     ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=55.0066    Group=...
    Group: ProductID=9      ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=17     ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=29     ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=53     ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=54     ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=55     ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=33.3700    Group=...
    Group: ProductID=7      ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=14     ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=28     ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=51     ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=74     ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  AveragePrice=21.6825    Group=...
    Group: ProductID=10     ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=13     ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=18     ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=30     ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=36     ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=37     ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=40     ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=41     ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=45     ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=46     ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=58     ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=73     ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }

  


GroupBy - Sum

This sample uses group by and Sum to find the total UnitPrice for each CategoryID.

Public Sub LinqToSqlGroupBy05()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into g = Group _
            Select New With {g, .TotalPrice = g.Sum(Function(p) p.UnitPrice)}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  g=...   TotalPrice=1227.5200
    g: ProductID=1  ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=2  ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=24         ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=34         ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=35         ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=38         ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=39         ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=43         ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=67         ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=70         ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=75         ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=76         ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=288.7500
    g: ProductID=3  ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=4  ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=5  ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=6  ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=8  ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=15         ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=44         ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=61         ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=63         ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=65         ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=66         ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=77         ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=340.0800
    g: ProductID=16         ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=19         ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=20         ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=21         ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=25         ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=26         ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=27         ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=47         ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=48         ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=49         ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=50         ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=62         ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=68         ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=297.3000
    g: ProductID=11         ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=12         ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=31         ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=32         ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=33         ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=59         ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=60         ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=69         ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=71         ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=72         ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=148.7500
    g: ProductID=22         ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=23         ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=42         ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=52         ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=56         ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=57         ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=64         ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=330.0400
    g: ProductID=9  ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=17         ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=29         ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=53         ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=54         ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=55         ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=166.8500
    g: ProductID=7  ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=14         ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=28         ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=51         ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=74         ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   TotalPrice=260.1900
    g: ProductID=10         ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=13         ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=18         ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=30         ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=36         ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=37         ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=40         ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=41         ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=45         ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=46         ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=58         ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=73         ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }

  


GroupBy - Count

This sample uses group by and Count to find the number of Products in each CategoryID.

Public Sub LinqToSqlGroupBy06()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into g = Group _
            Select New With {g, .NumProducts = g.Count()}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  g=...   NumProducts=12
    g: ProductID=1  ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=2  ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=24         ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=34         ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=35         ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=38         ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=39         ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=43         ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=67         ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=70         ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=75         ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=76         ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=12
    g: ProductID=3  ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=4  ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=5  ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=6  ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=8  ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=15         ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=44         ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=61         ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=63         ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=65         ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=66         ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=77         ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=13
    g: ProductID=16         ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=19         ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=20         ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=21         ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=25         ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=26         ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=27         ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=47         ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=48         ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=49         ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=50         ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=62         ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=68         ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=10
    g: ProductID=11         ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=12         ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=31         ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=32         ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=33         ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=59         ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=60         ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=69         ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=71         ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=72         ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=7
    g: ProductID=22         ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=23         ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=42         ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=52         ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=56         ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=57         ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=64         ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=6
    g: ProductID=9  ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=17         ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=29         ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=53         ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=54         ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=55         ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=5
    g: ProductID=7  ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=14         ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=28         ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=51         ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=74         ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=12
    g: ProductID=10         ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=13         ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=18         ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=30         ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=36         ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=37         ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=40         ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=41         ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=45         ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=46         ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=58         ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=73         ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }

  


GroupBy - Count - Conditional

This sample uses group by and Count to find the number of Products in each CategoryID that are discontinued.

Public Sub LinqToSqlGroupBy07()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into g = Group _
            Select New With {g, .NumProducts = g.Count(Function(p) p.Discontinued)}

    ObjectDumper.Write(q, 1)
End Sub


Result:
  g=...   NumProducts=1
    g: ProductID=1  ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=2  ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=24         ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=34         ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=35         ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=38         ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=39         ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=43         ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=67         ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=70         ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=75         ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=76         ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=1
    g: ProductID=3  ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=4  ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=5  ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=6  ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=8  ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=15         ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=44         ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=61         ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=63         ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=65         ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=66         ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=77         ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=0
    g: ProductID=16         ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=19         ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=20         ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=21         ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=25         ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=26         ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=27         ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=47         ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=48         ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=49         ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=50         ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=62         ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=68         ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=0
    g: ProductID=11         ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=12         ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=31         ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=32         ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=33         ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=59         ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=60         ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=69         ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=71         ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=72         ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=1
    g: ProductID=22         ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=23         ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=42         ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=52         ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=56         ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=57         ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=64         ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=4
    g: ProductID=9  ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=17         ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=29         ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=53         ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=54         ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=55         ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=1
    g: ProductID=7  ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=14         ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=28         ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=51         ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=74         ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  g=...   NumProducts=0
    g: ProductID=10         ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=13         ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=18         ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=30         ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=36         ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=37         ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=40         ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=41         ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=45         ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=46         ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=58         ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    g: ProductID=73         ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }

  


GroupBy - followed by Where

This sample uses a where clause after a group by clause to find all categories that have at least 10 products.

Public Sub LinqToSqlGroupBy08()
    Dim q = From p In db.Products _
            Group p By p.CategoryID Into Group _
            Where Group.Count() >= 10 _
            Select Group, ProductCount = Group.Count()

    ObjectDumper.Write(q, 1)
End Sub


Result:
  Group=...       ProductCount=12
    Group: ProductID=1      ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=2      ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=24     ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=34     ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=35     ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=38     ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=39     ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=43     ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=67     ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=70     ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=75     ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=76     ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  Group=...       ProductCount=12
    Group: ProductID=3      ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=4      ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=5      ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=6      ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=8      ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=15     ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=44     ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=61     ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=63     ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=65     ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=66     ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=77     ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  Group=...       ProductCount=13
    Group: ProductID=16     ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=19     ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=20     ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=21     ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=25     ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=26     ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=27     ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=47     ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=48     ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=49     ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=50     ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=62     ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=68     ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  Group=...       ProductCount=10
    Group: ProductID=11     ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=12     ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=31     ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=32     ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=33     ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=59     ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=60     ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=69     ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=71     ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=72     ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  Group=...       ProductCount=12
    Group: ProductID=10     ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=13     ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=18     ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=30     ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=36     ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=37     ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=40     ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=41     ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=45     ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=46     ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=58     ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=73     ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }

  


GroupBy - Multiple Columns

This sample uses Group By to group products by CategoryID and SupplierID.

Public Sub LinqToSqlGroupBy09()
    Dim categories = From p In db.Products _
                     Group By Key = New With {p.CategoryID, p.SupplierID} Into Group _
                     Select Key, Group

    ObjectDumper.Write(categories, 1)
End Sub


Result:
  Group=...       key={ }
    Group: ProductID=1      ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=2      ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=1
  Group=...       key={ }
    Group: ProductID=70     ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=7
  Group=...       key={ }
    Group: ProductID=24     ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=10
  Group=...       key={ }
    Group: ProductID=75     ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=12
  Group=...       key={ }
    Group: ProductID=34     ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=35     ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=67     ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=16
  Group=...       key={ }
    Group: ProductID=38     ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=39     ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=18
  Group=...       key={ }
    Group: ProductID=43     ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=20
  Group=...       key={ }
    Group: ProductID=76     ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=1       SupplierID=23
  Group=...       key={ }
    Group: ProductID=3      ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=1
  Group=...       key={ }
    Group: ProductID=4      ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=5      ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=65     ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=66     ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=2
  Group=...       key={ }
    Group: ProductID=6      ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=8      ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=3
  Group=...       key={ }
    Group: ProductID=15     ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=6
  Group=...       key={ }
    Group: ProductID=63     ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=7
  Group=...       key={ }
    Group: ProductID=77     ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=12
  Group=...       key={ }
    Group: ProductID=44     ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=20
  Group=...       key={ }
    Group: ProductID=61     ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=2       SupplierID=29
  Group=...       key={ }
    Group: ProductID=16     ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=7
  Group=...       key={ }
    Group: ProductID=19     ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=20     ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=21     ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=68     ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=8
  Group=...       key={ }
    Group: ProductID=25     ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=26     ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=27     ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=11
  Group=...       key={ }
    Group: ProductID=47     ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=48     ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=22
  Group=...       key={ }
    Group: ProductID=49     ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=50     ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=23
  Group=...       key={ }
    Group: ProductID=62     ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=3       SupplierID=29
  Group=...       key={ }
    Group: ProductID=11     ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=12     ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=4       SupplierID=5
  Group=...       key={ }
    Group: ProductID=31     ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=32     ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=72     ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=4       SupplierID=14
  Group=...       key={ }
    Group: ProductID=33     ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=69     ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=71     ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=4       SupplierID=15
  Group=...       key={ }
    Group: ProductID=59     ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=60     ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=4       SupplierID=28
  Group=...       key={ }
    Group: ProductID=22     ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=23     ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=5       SupplierID=9
  Group=...       key={ }
    Group: ProductID=64     ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=5       SupplierID=12
  Group=...       key={ }
    Group: ProductID=42     ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=5       SupplierID=20
  Group=...       key={ }
    Group: ProductID=52     ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=5       SupplierID=24
  Group=...       key={ }
    Group: ProductID=56     ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=57     ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=5       SupplierID=26
  Group=...       key={ }
    Group: ProductID=9      ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=6       SupplierID=4
  Group=...       key={ }
    Group: ProductID=17     ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=6       SupplierID=7
  Group=...       key={ }
    Group: ProductID=29     ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=6       SupplierID=12
  Group=...       key={ }
    Group: ProductID=53     ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=6       SupplierID=24
  Group=...       key={ }
    Group: ProductID=54     ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=55     ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=6       SupplierID=25
  Group=...       key={ }
    Group: ProductID=7      ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=7       SupplierID=3
  Group=...       key={ }
    Group: ProductID=74     ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=7       SupplierID=4
  Group=...       key={ }
    Group: ProductID=14     ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=7       SupplierID=6
  Group=...       key={ }
    Group: ProductID=28     ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=7       SupplierID=12
  Group=...       key={ }
    Group: ProductID=51     ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=7       SupplierID=24
  Group=...       key={ }
    Group: ProductID=10     ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=4
  Group=...       key={ }
    Group: ProductID=13     ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=6
  Group=...       key={ }
    Group: ProductID=18     ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=7
  Group=...       key={ }
    Group: ProductID=30     ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=13
  Group=...       key={ }
    Group: ProductID=36     ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=37     ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=73     ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=17
  Group=...       key={ }
    Group: ProductID=40     ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=41     ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=19
  Group=...       key={ }
    Group: ProductID=45     ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    Group: ProductID=46     ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=21
  Group=...       key={ }
    Group: ProductID=58     ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    key: CategoryID=8       SupplierID=27

  


GroupBy - Expression

This sample uses Group By to return two sequences of products. The first sequence contains products with unit price greater than 10. The second sequence contains products with unit price less than or equal to 10.

Public Sub LinqToSqlGroupBy10()
    Dim categories = From p In db.Products _
                     Group p By Key = New With {.Criterion = p.UnitPrice > 10} Into Group _
                     Select Group

    ObjectDumper.Write(categories, 1)
End Sub


Result:
  ...
    ProductID=13    ProductName=Konbu       SupplierID=6    CategoryID=8    QuantityPerUnit=2 kg box        UnitPrice=7.0000        UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=23    ProductName=Tunnbröd    SupplierID=9    CategoryID=5    QuantityPerUnit=12 - 250 g pkgs.        UnitPrice=10.0000       UnitsInStock=61         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=24    ProductName=Guaraná Fantástica  SupplierID=10   CategoryID=1    QuantityPerUnit=12 - 355 ml cans        UnitPrice=5.5000        UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=33    ProductName=Geitost     SupplierID=15   CategoryID=4    QuantityPerUnit=500 g   UnitPrice=3.5000        UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=52    ProductName=Filo Mix    SupplierID=24   CategoryID=5    QuantityPerUnit=16 - 2 kg boxes         UnitPrice=8.0000        UnitsInStock=38         UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=54    ProductName=Tourtière   SupplierID=25   CategoryID=6    QuantityPerUnit=16 pies         UnitPrice=8.4500        UnitsInStock=21         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=75    ProductName=Rhönbräu Klosterbier        SupplierID=12   CategoryID=1    QuantityPerUnit=24 - 0.5 l bottles      UnitPrice=8.7500        UnitsInStock=125        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
  ...
    ProductID=1     ProductName=Chai        SupplierID=1    CategoryID=1    QuantityPerUnit=10 boxes x 20 bags      UnitPrice=778.7700      UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=2     ProductName=Chang       SupplierID=1    CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=20.0000       UnitsInStock=17         UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=3     ProductName=Aniseed Syrup       SupplierID=1    CategoryID=2    QuantityPerUnit=12 - 550 ml bottles     UnitPrice=11.0000       UnitsInStock=13         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=4     ProductName=Chef Anton's Cajun Seasoning        SupplierID=2    CategoryID=2    QuantityPerUnit=48 - 6 oz jars  UnitPrice=23.0000       UnitsInStock=53         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=5     ProductName=Chef Anton's Gumbo Mix      SupplierID=2    CategoryID=2    QuantityPerUnit=36 boxes        UnitPrice=22.3500       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=6     ProductName=Grandma's Boysenberry Spread        SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 8 oz jars  UnitPrice=26.0000       UnitsInStock=120        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=7     ProductName=Uncle Bob's Organic Dried Pears     SupplierID=3    CategoryID=7    QuantityPerUnit=12 - 1 lb pkgs.         UnitPrice=31.0000       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=8     ProductName=Northwoods Cranberry Sauce  SupplierID=3    CategoryID=2    QuantityPerUnit=12 - 12 oz jars         UnitPrice=41.0000       UnitsInStock=6  UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=9     ProductName=Mishi Kobe Niku     SupplierID=4    CategoryID=6    QuantityPerUnit=18 - 500 g pkgs.        UnitPrice=98.0000       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=10    ProductName=Ikura       SupplierID=4    CategoryID=8    QuantityPerUnit=12 - 200 ml jars        UnitPrice=32.0000       UnitsInStock=31         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=11    ProductName=Queso Cabrales      SupplierID=5    CategoryID=4    QuantityPerUnit=1 kg pkg.       UnitPrice=22.0000       UnitsInStock=22         UnitsOnOrder=30         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=12    ProductName=Queso Manchego La Pastora   SupplierID=5    CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=39.0000       UnitsInStock=86         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=14    ProductName=Tofu        SupplierID=6    CategoryID=7    QuantityPerUnit=40 - 100 g pkgs.        UnitPrice=24.2500       UnitsInStock=35         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=15    ProductName=Genen Shouyu        SupplierID=6    CategoryID=2    QuantityPerUnit=24 - 250 ml bottles     UnitPrice=16.5000       UnitsInStock=39         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=16    ProductName=Pavlova     SupplierID=7    CategoryID=3    QuantityPerUnit=32 - 500 g boxes        UnitPrice=18.4500       UnitsInStock=29         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=17    ProductName=Alice Mutton        SupplierID=7    CategoryID=6    QuantityPerUnit=20 - 1 kg tins  UnitPrice=40.0000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=18    ProductName=Carnarvon Tigers    SupplierID=7    CategoryID=8    QuantityPerUnit=16 kg pkg.      UnitPrice=63.5000       UnitsInStock=42         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=19    ProductName=Teatime Chocolate Biscuits  SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 12 pieces    UnitPrice=10.2000       UnitsInStock=25         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=20    ProductName=Sir Rodney's Marmalade      SupplierID=8    CategoryID=3    QuantityPerUnit=30 gift boxes   UnitPrice=82.0000       UnitsInStock=40         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=21    ProductName=Sir Rodney's Scones         SupplierID=8    CategoryID=3    QuantityPerUnit=24 pkgs. x 4 pieces     UnitPrice=11.0000       UnitsInStock=3  UnitsOnOrder=40         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=22    ProductName=Gustaf's Knäckebröd         SupplierID=9    CategoryID=5    QuantityPerUnit=24 - 500 g pkgs.        UnitPrice=22.0000       UnitsInStock=104        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=25    ProductName=NuNuCa Nuß-Nougat-Creme     SupplierID=11   CategoryID=3    QuantityPerUnit=20 - 450 g glasses      UnitPrice=15.0000       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=26    ProductName=Gumbär Gummibärchen         SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 250 g bags        UnitPrice=32.2300       UnitsInStock=15         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=27    ProductName=Schoggi Schokolade  SupplierID=11   CategoryID=3    QuantityPerUnit=100 - 100 g pieces      UnitPrice=44.9000       UnitsInStock=49         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=28    ProductName=Rössle Sauerkraut   SupplierID=12   CategoryID=7    QuantityPerUnit=25 - 825 g cans         UnitPrice=46.6000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=29    ProductName=Thüringer Rostbratwurst     SupplierID=12   CategoryID=6    QuantityPerUnit=50 bags x 30 sausgs.    UnitPrice=124.7900      UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=30    ProductName=Nord-Ost Matjeshering       SupplierID=13   CategoryID=8    QuantityPerUnit=10 - 200 g glasses      UnitPrice=26.8900       UnitsInStock=10         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=31    ProductName=Gorgonzola Telino   SupplierID=14   CategoryID=4    QuantityPerUnit=12 - 100 g pkgs         UnitPrice=13.5000       UnitsInStock=0  UnitsOnOrder=70         ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=32    ProductName=Mascarpone Fabioli  SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=33.0000       UnitsInStock=9  UnitsOnOrder=40         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=34    ProductName=Sasquatch Ale       SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=111        UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=35    ProductName=Steeleye Stout      SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=19.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=36    ProductName=Inlagd Sill         SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 250 g  jars        UnitPrice=20.0000       UnitsInStock=112        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=37    ProductName=Gravad lax  SupplierID=17   CategoryID=8    QuantityPerUnit=12 - 500 g pkgs.        UnitPrice=27.0000       UnitsInStock=11         UnitsOnOrder=50         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=38    ProductName=Côte de Blaye       SupplierID=18   CategoryID=1    QuantityPerUnit=12 - 75 cl bottles      UnitPrice=264.5000      UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=39    ProductName=Chartreuse verte    SupplierID=18   CategoryID=1    QuantityPerUnit=750 cc per bottle       UnitPrice=19.0000       UnitsInStock=69         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=40    ProductName=Boston Crab Meat    SupplierID=19   CategoryID=8    QuantityPerUnit=24 - 4 oz tins  UnitPrice=19.4000       UnitsInStock=123        UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=41    ProductName=Jack's New England Clam Chowder     SupplierID=19   CategoryID=8    QuantityPerUnit=12 - 12 oz cans         UnitPrice=10.6500       UnitsInStock=85         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=42    ProductName=Singaporean Hokkien Fried Mee       SupplierID=20   CategoryID=5    QuantityPerUnit=32 - 1 kg pkgs.         UnitPrice=15.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=43    ProductName=Ipoh Coffee         SupplierID=20   CategoryID=1    QuantityPerUnit=16 - 500 g tins         UnitPrice=47.0000       UnitsInStock=17         UnitsOnOrder=10         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=44    ProductName=Gula Malacca        SupplierID=20   CategoryID=2    QuantityPerUnit=20 - 2 kg bags  UnitPrice=20.4500       UnitsInStock=27         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=45    ProductName=Rogede sild         SupplierID=21   CategoryID=8    QuantityPerUnit=1k pkg.         UnitPrice=10.5000       UnitsInStock=5  UnitsOnOrder=70         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=46    ProductName=Spegesild   SupplierID=21   CategoryID=8    QuantityPerUnit=4 - 450 g glasses       UnitPrice=13.0000       UnitsInStock=95         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=47    ProductName=Zaanse koeken       SupplierID=22   CategoryID=3    QuantityPerUnit=10 - 4 oz boxes         UnitPrice=10.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=48    ProductName=Chocolade   SupplierID=22   CategoryID=3    QuantityPerUnit=10 pkgs.        UnitPrice=13.7500       UnitsInStock=15         UnitsOnOrder=70         ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=49    ProductName=Maxilaku    SupplierID=23   CategoryID=3    QuantityPerUnit=24 - 50 g pkgs.         UnitPrice=21.0000       UnitsInStock=10         UnitsOnOrder=60         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=50    ProductName=Valkoinen suklaa    SupplierID=23   CategoryID=3    QuantityPerUnit=12 - 100 g bars         UnitPrice=17.2500       UnitsInStock=65         UnitsOnOrder=0  ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=51    ProductName=Manjimup Dried Apples       SupplierID=24   CategoryID=7    QuantityPerUnit=50 - 300 g pkgs.        UnitPrice=54.0000       UnitsInStock=20         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=53    ProductName=Perth Pasties       SupplierID=24   CategoryID=6    QuantityPerUnit=48 pieces       UnitPrice=33.8000       UnitsInStock=0  UnitsOnOrder=0  ReorderLevel=0  Discontinued=True       Order_Details=...       Category={ }    Supplier={ }
    ProductID=55    ProductName=Pâté chinois        SupplierID=25   CategoryID=6    QuantityPerUnit=24 boxes x 2 pies       UnitPrice=25.0000       UnitsInStock=115        UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=56    ProductName=Gnocchi di nonna Alice      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=39.0000       UnitsInStock=21         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=57    ProductName=Ravioli Angelo      SupplierID=26   CategoryID=5    QuantityPerUnit=24 - 250 g pkgs.        UnitPrice=20.5000       UnitsInStock=36         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=58    ProductName=Escargots de Bourgogne      SupplierID=27   CategoryID=8    QuantityPerUnit=24 pieces       UnitPrice=14.2500       UnitsInStock=62         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=59    ProductName=Raclette Courdavault        SupplierID=28   CategoryID=4    QuantityPerUnit=5 kg pkg.       UnitPrice=56.0000       UnitsInStock=79         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=60    ProductName=Camembert Pierrot   SupplierID=28   CategoryID=4    QuantityPerUnit=15 - 300 g rounds       UnitPrice=35.0000       UnitsInStock=19         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=61    ProductName=Sirop d'érable      SupplierID=29   CategoryID=2    QuantityPerUnit=24 - 500 ml bottles     UnitPrice=29.5000       UnitsInStock=113        UnitsOnOrder=0  ReorderLevel=25         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=62    ProductName=Tarte au sucre      SupplierID=29   CategoryID=3    QuantityPerUnit=48 pies         UnitPrice=50.3000       UnitsInStock=17         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=63    ProductName=Vegie-spread        SupplierID=7    CategoryID=2    QuantityPerUnit=15 - 625 g jars         UnitPrice=44.9000       UnitsInStock=24         UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=64    ProductName=Wimmers gute Semmelknödel   SupplierID=12   CategoryID=5    QuantityPerUnit=20 bags x 4 pieces      UnitPrice=34.2500       UnitsInStock=22         UnitsOnOrder=80         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=65    ProductName=Louisiana Fiery Hot Pepper Sauce    SupplierID=2    CategoryID=2    QuantityPerUnit=32 - 8 oz bottles       UnitPrice=22.0500       UnitsInStock=76         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=66    ProductName=Louisiana Hot Spiced Okra   SupplierID=2    CategoryID=2    QuantityPerUnit=24 - 8 oz jars  UnitPrice=18.0000       UnitsInStock=4  UnitsOnOrder=100        ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=67    ProductName=Laughing Lumberjack Lager   SupplierID=16   CategoryID=1    QuantityPerUnit=24 - 12 oz bottles      UnitPrice=15.0000       UnitsInStock=52         UnitsOnOrder=0  ReorderLevel=10         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=68    ProductName=Scottish Longbreads         SupplierID=8    CategoryID=3    QuantityPerUnit=10 boxes x 8 pieces     UnitPrice=13.5000       UnitsInStock=6  UnitsOnOrder=10         ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=69    ProductName=Gudbrandsdalsost    SupplierID=15   CategoryID=4    QuantityPerUnit=10 kg pkg.      UnitPrice=37.0000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=70    ProductName=Outback Lager       SupplierID=7    CategoryID=1    QuantityPerUnit=24 - 355 ml bottles     UnitPrice=16.0000       UnitsInStock=15         UnitsOnOrder=10         ReorderLevel=30         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=71    ProductName=Flotemysost         SupplierID=15   CategoryID=4    QuantityPerUnit=10 - 500 g pkgs.        UnitPrice=22.5000       UnitsInStock=26         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=72    ProductName=Mozzarella di Giovanni      SupplierID=14   CategoryID=4    QuantityPerUnit=24 - 200 g pkgs.        UnitPrice=35.8000       UnitsInStock=14         UnitsOnOrder=0  ReorderLevel=0  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=73    ProductName=Röd Kaviar  SupplierID=17   CategoryID=8    QuantityPerUnit=24 - 150 g jars         UnitPrice=16.0000       UnitsInStock=101        UnitsOnOrder=0  ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=74    ProductName=Longlife Tofu       SupplierID=4    CategoryID=7    QuantityPerUnit=5 kg pkg.       UnitPrice=11.0000       UnitsInStock=4  UnitsOnOrder=20         ReorderLevel=5  Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=76    ProductName=Lakkalikööri        SupplierID=23   CategoryID=1    QuantityPerUnit=500 ml  UnitPrice=19.0000       UnitsInStock=57         UnitsOnOrder=0  ReorderLevel=20         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }
    ProductID=77    ProductName=Original Frankfurter grüne Soße     SupplierID=12   CategoryID=2    QuantityPerUnit=12 boxes        UnitPrice=14.0000       UnitsInStock=32         UnitsOnOrder=0  ReorderLevel=15         Discontinued=False      Order_Details=...       Category={ }    Supplier={ }