title: InvalidOperationException: The LINQ expression for groupby
body: <p>I'm implementing an asp.net core project. I wrote a query like below in my code, </p>
  
  <pre><code>var RegisteredReqStatus = (from t1 in _context.Apiapplicant
                                         join t2 in _context.ApiApplicantHistory on t1.Id equals t2.ApiApplicantId
                                         join t3 in _context.EntityType on t2.LastReqStatus equals t3.Id
                                         where t1.IsDeleted.Equals(false) &amp;&amp; t1.LastRequestStatus == t2.Id
                                         group t2 by t2.LastReqStatus into ApiAppGp
                                         select new
                                         {
                                             lastReqName = ApiAppGp.FirstOrDefault().LastReqStatusNavigation.Name,
                                             ReqCount = ApiAppGp.Count()
                                         }).ToList();
  </code></pre>
  
  <p>but after running my project, it shows me an error like below:</p>
  
  <blockquote>
    <p>InvalidOperationException: The LINQ expression
    '(GroupByShaperExpression: KeySelector: (a.lastReqStatus),
    ElementSelector:(EntityShaperExpression: EntityType:
    ApiApplicantHistory ValueBufferExpression:
    (ProjectionBindingExpression: EmptyProjectionMember) IsNullable: False
    ) )
    .FirstOrDefault()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See <a href="https://go.microsoft.com/fwlink/?linkid=2101038" rel="nofollow noreferrer">https://go.microsoft.com/fwlink/?linkid=2101038</a> for more information.</p>
  </blockquote>
  
  <p>And here is my data models:</p>
  
  <pre><code>public partial class ApiApplicantHistory
      {
          public int Id { get; set; }
          public int? SentType { get; set; }
          public int? Reason { get; set; }
          public int? LastReqStatus { get; set; }
  
  
          public virtual Apiapplicant ApiApp { get; set; }
          public virtual EntityType LastReqStatusNavigation { get; set; }
          public virtual EntityType SentTypeNavigation { get; set; }
          public virtual EntityType ReasonNavigation { get; set; }
      }
  
   public partial class EntityType
      {
          public EntityType()
          {
  ApiApplicantHistoryLastReqStatusNavigation = new HashSet&lt;ApiApplicantHistory&gt;();            ApiApplicantHistorySentTypeNavigation = new HashSet&lt;ApiApplicantHistory&gt;();
              ApiApplicantHistoryReasonNavigation = new HashSet&lt;ApiApplicantHistory&gt;();
          }
  
          public int Id { get; set; }
          public string Name { get; set; }
          public string EntityKey { get; set; }
  
  public virtual ICollection&lt;ApiApplicantHistory&gt; ApiApplicantHistoryLastReqStatusNavigation { get; set; }        public virtual ICollection&lt;ApiApplicantHistory&gt; ApiAppHistorySentTypeNavigation { get; set; }
          public virtual ICollection&lt;ApiApplicantHistory&gt; ApiAppHistoryReasonNavigation { get; set; }
  
      }
  }
  
  public partial class Apiapplicant
      {
          public Apiapplicant()
          {
              ApiApplicantHistory = new HashSet&lt;ApiApplicantHistory&gt;();
          }
  
          public int Id { get; set; }
  public bool? IsDeleted { get; set; }
  
          public int? LastRequestStatus { get; set; }
  
          public virtual ICollection&lt;ApiApplicantHistory&gt; ApiApplicantHistory { get; set; }
      }
  </code></pre>
  
  <p>I appreciate if anyone can suggest me a solution.</p>