title: How to get Count in Lambda
body: <p>I have three models (Applicant, Meeting, City) and I joined three of them. I want to get Count by grouping MeetingId in Applicant model. Here are my models and method I use for populating Dropdownlist in Controller. So, like the <strong>"Expired"</strong> property in the Controller,  how can I obtain the count for the MeetingId by grouping on <strong>"TotalMeetingById"</strong> property? </p>
  
  <p><br/></p>
  
  <p><strong>Applicant Model:</strong></p>
  
  <pre><code>public class Applicant
  {
      public int ApplicantID { get; set; }
      public DateTime? SubmitDate { get; set; }
      public string Name { get; set; }
      public string Surname { get; set; }   
      public int MeetingId { get; set; }
  }
  </code></pre>
  
  <p><br/>
  <strong>Meeting Model:</strong></p>
  
  <pre><code>public class Meeting
  {
      public int MeetingID { get; set; }
      public string MeetingName { get; set; }
      public DateTime MeetingStartDate { get; set; }       
      public DateTime? MeetingEndDate { get; set; }
      public int? TotalParticipant { get; set; }
      public int? MeetingCityId { get; set; } 
  
      public int? ParticipantCityAId { get; set; }
      public int? ParticipantCityBId { get; set; }
  }
  </code></pre>
  
  <p><br/>
  <strong>City Model:</strong></p>
  
  <pre><code>public class City
  {
      public int CityID { get; set; }
      public string CityName { get; set; }
  }    
  </code></pre>
  
  <p><br/>
  <strong>Controller:</strong></p>
  
  <pre><code>private void PopulateDropDownList()
  {
      var meetingsQuery = repository.Meetings
          .GroupJoin(repository.Cities, m =&gt; m.MeetingCityId, c =&gt; c.CityID, (m, c) =&gt; new { m, cA = c.DefaultIfEmpty() })
          .SelectMany(z =&gt; z.cA.Select(cA =&gt; new { m = z.m, cA }))
          .GroupJoin(repository.Cities, m =&gt; m.m.ParticipantCityAId, c =&gt; c.CityID, (m, c) =&gt; new { m.m, m.cA, cB = c.DefaultIfEmpty() })
          .SelectMany(w =&gt; w.cB.Select(cB =&gt; new { m = w.m, cA = w.cA, cB }))
          .GroupJoin(repository.Cities, m =&gt; m.m.ParticipantCityBId, c =&gt; c.CityID, (m, c) =&gt; new { m.m, m.cA, m.cB, cC = c.DefaultIfEmpty() })
          .SelectMany(t =&gt; t.cC.Select(cC =&gt; new { m = t.m, cA = t.cA, cB = t.cB, cC }))
          .Select(
              m =&gt;
                  new
                  {
                      CityID = m.cA.CityID,
                      CityName = m.cA.CityName,
                      MeetingDate = m.m.MeetingStartDate,
                      MeetingName = m.m.MeetingName,
                      NameofMeetingCityIdA = m.cA != null ? m.cA.CityName : null,
                      NameofMeetingCityIdB = m.cB != null ? m.cB.CityName : null,
                      NameofMeetingCityIdC = m.cC != null ? m.cC.CityName : null
                  })
          .OrderBy(x =&gt; x.CityID)
          .AsEnumerable()
          .Select(
              i =&gt; new
              {
                  Value = i.CityID.ToString(),
                  DisplayValue = string.Format("{0} ({1:dd MMMM yyyy})", i.NameofMeetingCityIdA, i.MeetingDate),
                  Expired = i.MeetingDate &lt; DateTime.UtcNow,
                  TotalMeetingById= ??? &gt;&gt;&gt; I cannot get the total count for the related MeetingId at here
              }
          ).ToList();
  
      var selectItems = new List&lt;MyHelpers.MySelectItem&gt;(meetingsQuery.Count);
      foreach (var record in meetingsQuery)
      {
          var item = new MyHelpers.MySelectItem
          {
              Text = record.DisplayValue,
              Value = record.Value
          };
          if (record.Expired)
          {
              item.Class = "disabled";
              item.Disabled = "disabled";
          }
          selectItems.Add(item);
      }
      ViewBag.MeetingData = selectItems;
  } 
  </code></pre>
  
  <p><br/>
  <br/>
  Here are sample data for models:</p>
  
  <p><br/>
  <strong>Applicant:</strong></p>
  
  <pre><code> ApplicantID : 100
   SubmitDate : 01/11/2013
   Name : Christof
   Surname : Jahnsen 
   MeetingId : 1
  </code></pre>
  
  <p><br/></p>
  
  <p><strong>Meeting:</strong></p>
  
  <pre><code> MeetingID : 1
   MeetingName : City Information Days
   MeetingStartDate : 01/01/2014       
   MeetingEndDate : 02/01/2014
   TotalParticipant : 2 (for example) 
   MeetingCityId : 500
   ParticipantCityAId : 501
   ParticipantCityBId : 502
  </code></pre>
  
  <p><br/></p>
  
  <p><strong>City:</strong></p>
  
  <pre><code>CityID : 500 / 501 / 502
  CityName : London / Paris / NY
  </code></pre>
  
  <p><br/>
  <strong>Update -----------------------------------------------------------------------</strong></p>
  
  <p><strong>Razor:</strong></p>
  
  <pre><code>@Html.LabelFor(m =&gt; m.Applicant.MeetingId)
  @Html.MyDropdownListFor(m =&gt; m.Applicant.MeetingId, ViewBag.MeetingData as List&lt;MyHelpers.MySelectItem&gt;, "---- Select ----",
          new { name = "meetingId", id = "meetingId" })
  @Html.ValidationMessageFor(m =&gt; m.Applicant.MeetingId, null, new { @class = "ValidationErrors" })
  </code></pre>
  
  <p><br/></p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public ViewResult Add()
  {
      PopulateDropDownList();
  
      ApplicantViewModel model = new ApplicantViewModel
      {
          Applicant = new Applicant(),
          Applicants = repository.Applicants,
          Lookups = repository.Lookups,
          Cities = repository.Cities
          .ToList()
          };
          return View(model);
      }
  
  [HttpPost]
  public ActionResult Add(ApplicantViewModel model)
  {
      ApplicantViewModel viewModel;
  
      if (ModelState.IsValid)
      {
          model.Applicant.SubmitDate = DateTime.Now;
          repository.SaveApplicant(model.Applicant);
          PopulateDropDownList(model.Applicant);
          return View("Completed", ViewBag.ApplicantId = model.Applicant.ApplicantID);
      }
      else
      {
          // there is something wrong with the data values
          PopulateDropDownList();
          TempData["message"] = "Please try again.";
          viewModel = new ApplicantViewModel
          {
              Applicant = new Applicant(),
              Applicants = repository.Applicants,
              Lookups = repository.Lookups,
              Cities = repository.Cities
              .ToList()
          };
          return View(viewModel);
      }
  }
  </code></pre>