title: LINQ and Entity Framework, get sum of related rows of a non mapped column
body: <p>I want to get the sum of applicants that applied to a specific position, this should not be saved as a column.</p>
  
  <p>My model is simple:</p>
  
  <p>We have positions:</p>
  
  <ul>
  <li><p>net developer</p></li>
  <li><p>java developer</p></li>
  </ul>
  
  <p>We have applicants:</p>
  
  <ul>
  <li>Luis</li>
  <li>John</li>
  <li>etc</li>
  </ul>
  
  <p>We have applicants per position</p>
  
  <p>With this column or property  I want to know how many people have applied to each position, depending on the status.
  So in my mvc view I want to show something like:</p>
  
  <p>Position       Applied    Accepted  Rejected ... other status</p>
  
  <p>.net developer     5         3         2</p>
  
  <p>java developer     3         2         1</p>
  
  <p>The real problem here is the linq query which I am not very expert.</p>
  
  <p>EDIT:  I think I needed to change where the linq query must be coded, I suppose it should be in the ApplicantPosition class instead of Position, I also changed the types of Position  and Application to be ICollection.</p>
  
  <p>Please see the modified code.</p>
  
  <pre><code> public class Position
      {
          public int id { get; set; }
  
          [StringLength(20, MinimumLength=3)]
          public string name { get; set; }
          public int yearsExperienceRequired { get; set; }
  
  
      }
  
      public class Applicant
      {
          public int ApplicantId { get; set; }
          [StringLength(20, MinimumLength = 3)]
          public string name { get; set; }
          public string telephone { get; set; }
          public string skypeuser { get; set; }
          public ApplicantImage photo { get; set; }
      }
  
  public class ApplicantPosition
  {
      public virtual ICollection&lt;Position&gt; appliedPositions { get; set; }
      public virtual ICollection&lt;Applicant&gt; applicants { get; set; }
      public DateTime appliedDate { get; set; }
      public int StatusValue { get; set; }
  
      public Status Status
      {
          get { return (Status)StatusValue; }
          set { StatusValue = (int)value; }
      }
  
        [NotMapped]
      public int numberOfApplicantsApplied
      {
          get
          {
              var query = 
                  from ap in appliedPositions 
                  select new
                  {
                      positionName = g.Key.name,
                      peopleApplied = g.Count(x =&gt; x.Status == Status.Applied),
                  };
              return query.Count(); ---??
          }
      }
  }
  </code></pre>