title: Create a dynamic group by Query in Linq
body: <p>I have a form with 4 checkbox for grouping , when I want to create LINQ dynamic query in where clause, it is very easy to use something like this : </p>
  
  <pre><code>  query = query.where(x=&gt;x.blah == blahblah).asQueryable();
  </code></pre>
  
  <p>but I can't simulate this type of coding for Group by clause. I need something like this :</p>
  
  <pre><code>if(blah1==true)
      query = query.GroupBy(x=&gt;x.Blah1).select(smthing);
  if(blah2==true)
      query = query.GroupBy(x=&gt;x.Blah2).select(smthing);
  if(blah3==true)
      query = query.GroupBy(x=&gt;x.Blah3).select(smthing);
   ....
  </code></pre>
  
  <p>How can I do this kind of query? some post in stackoverflow show misunderstanding code like Expression> . Please show <a href="http://translateyar.ir" rel="nofollow noreferrer">me</a> an easy and applicable way.</p>