Linq and Lambda Expression get count for group and distinct
<p>I've been trying to get the "Count" for my "Value" field in my query expression. In my code it suppose to create a list of checkboxes and beside the checkboxes is a count of how many items are in the list(checkbox). </p>

<p>Could someone show me how to get the count for the items of my field Value this is a checbox filtering system I'm making.I've just started learning linq and lambda exressions.</p>

<p>Code in C# ASP.NET</p>

<pre><code>var dept = Page.RouteData.Values["department"];
var department = (from d in db.Departments where d.Name.Replace(" ", "-") == dept select new {d.Id, d.Name}).FirstOrDefault();

 var query = (from p in db.Products
              join f in db.ProductFilters on p.Id equals f.ProductId into filters
              from x in filters.Where(x =&gt; x.Product.DepartmentId == department.Id)                            
              select new { x.Id, x.Name, x.Value }).ToList();

 var brand = query.Where(x =&gt; x.Name == "Brand").OrderBy(x =&gt; x.Value);
 var price = query.Where(x =&gt; x.Name == "Price").OrderBy(x =&gt; x.Value);

 var brandAndPrice = brand.Concat(price);

 var labelBrandAndPrice = (from f in brandAndPrice select new { f.Name }).Distinct().OrderBy(x =&gt; x.Name);
 //var otherFilters = query.Except(brandAndPrice);

 StringBuilder sb = new StringBuilder();
 sb.Append("&lt;div class=\"Filters\"&gt;");                
 foreach (var label in labelBrandAndPrice)
 {
     sb.Append("&lt;span&gt;" + label.Name + "&lt;/span&gt;&lt;br /&gt;");
     sb.Append("&lt;div class=\"ProdFilters\"&gt;");
     // Below is where I wanted to do distinct expression and groupby but it didn't work
     var BrandPriceCollection = brandAndPrice.Where(x =&gt; x.Name == label.Name).Distinct().ToList();
     foreach (var bp in BrandPriceCollection)
     {
        //Here i want to write out the count for the field Value 
        sb.Append("&lt;input type=\"checkbox\" id=\"" + bp.Value + "\" /&gt;&lt;span&gt;" + bp.Value + "(" + "Count" + ")" + "&lt;/span&gt;&lt;br /&gt;");
     }
     sb.Append("&lt;/div&gt;");
 }               
 sb.Append("&lt;/div&gt;");
</code></pre>
