title: LINQ Method Syntax - how to accomplish dynamic Linq statements
body: <p>I use Linq to Entities to retrieve my records from DB. The function below is in a method. Method has some parameters (arguments) like  group, datefrom, dateto, place, state , searchtext etc. etc. </p>
  
  <p>the whole idea is if these parameters are not empty or null then accomplish the LINQ statments. The way I'm doing is I'm checking whether there is a value or not. if it has the value then I pass e.g. a.no_group= group if it doesn't has a value then I pass a statement like a.id!=-1, which is always true. </p>
  
  <p><strong>Problem:</strong>
  I mean I'm not happy with passing in every statement like "<strong>a.id != -1</strong>" which is always true . I use this because I have to put a value there. But I'm not happy with this way of doing it... (it works!)</p>
  
  <p><strong>Question:</strong>
  The question is: this right way of doing? 
  1- Can I replace a.id != -1 with something else ?</p>
  
  <p>2- If you see the whole linq statement is duplicated because of language check. As you see the last 
  linq statement checks on language 'Dutch' or 'French'...  How to avoid dupliation?</p>
  
  <p>3- I'm checking whether the current date (datetime.now) is between date_begin and date_end. Is this correct way...</p>
  
  <p>The whole code works fine, but I think I'm complicating the code which can be much simpler... </p>
  
  <p>But how?</p>
  
  <pre><code>if (Language == ConfBouwHelper.LanguageEnum.French)
  {
  //FRENCH RECORDS
   listAgendaItems = dc.agenda.Where(a =&gt;
     ((String.IsNullOrEmpty(group)) ? (a.id != -1) : (a.no_group == group))
  &amp;&amp; ((activityType.Equals("ALL")) ? (a.id != -1) : (a.type_manifestation == activityType))
  &amp;&amp; ((String.IsNullOrEmpty(dateFrom)) ? (a.id != -1) : (a.date_debut.Value &gt;= dateFrom))
  &amp;&amp; ((String.IsNullOrEmpty(dateTo)) ? (a.id != -1) : (a.date_debut.Value &lt;= dateTo))
  &amp;&amp; ((String.IsNullOrEmpty(place)) ? (a.id != -1) : (a.emplacement.Contains(place)))
  &amp;&amp; ((String.IsNullOrEmpty(state)) ? (a.id != -1) : (a.cd_prov == state))
  &amp;&amp; ((String.IsNullOrEmpty(searchText)) ? (a.id != -1) : (a.libelle_activite.Contains(searchText)))
  &amp;&amp; ((a.date_begin_display.HasValue ? DateTime.Now &gt;= a.date_begin_display.Value : a.id != -1) &amp;&amp;
     (a.date_end_display.HasValue ? DateTime.Now &lt;= a.date_end_display.Value : a.id != -1))
  &amp;&amp; (a.langue == "FRENCH" || a.langue == "B")).ToList&lt;agenda&gt;(); //GET FRENCH
  }
  else
  //DUTCH RECORDS
  {
   listAgendaItems = dc.agenda.Where(a =&gt;
     ((String.IsNullOrEmpty(group)) ? (a.id != -1) : (a.no_group == group))
  &amp;&amp; ((activityType.Equals("ALL")) ? (a.id != -1) : (a.type_manifestation == activityType))
  &amp;&amp; ((String.IsNullOrEmpty(dateFrom)) ? (a.id != -1) : (a.date_debut.Value &gt;= dateFrom))
  &amp;&amp; ((String.IsNullOrEmpty(dateTo)) ? (a.id != -1) : (a.date_debut.Value &lt;= dateTo))
  &amp;&amp; ((String.IsNullOrEmpty(place)) ? (a.id != -1) : (a.emplacement.Contains(place)))
  &amp;&amp; ((String.IsNullOrEmpty(state)) ? (a.id != -1) : (a.cd_prov == state))
  &amp;&amp; ((String.IsNullOrEmpty(searchText)) ? (a.id != -1) : (a.libelle_activite.Contains(searchText)))
  &amp;&amp; ((a.date_begin_display.HasValue ? DateTime.Now &gt;= a.date_begin_display.Value : a.id != -1) &amp;&amp;
     (a.date_end_display.HasValue ? DateTime.Now &lt;= a.date_end_display.Value : a.id != -1))
  
  &amp;&amp; (a.langue == "DUTCH" || a.langue == "B")).ToList&lt;agenda&gt;(); //GET DUTCH
  }
  </code></pre>