title: Dynamic where clause in LINQ?
body: <p>I am trying to load data based on Dynamic where condition. </p>
  
  <pre><code>string tempQry = string.Empty;
  if (!string.IsNullOrEmpty(cusid) &amp;&amp; !string.IsNullOrEmpty(mktid))
      tempQry = "x=&gt;x.MarketID==" + mktid + "&amp;&amp; x.MasterCustomerID==" + cusid;
  if (string.IsNullOrEmpty(cusid)) 
      tempQry = "x=&gt;x.MarketID==" + mktid;
  if (string.IsNullOrEmpty(mktid)) 
      tempQry = "x=&gt;x.MasterCustomerID==" + cusid;
  
  _lstOptInInterest = new LinkedList&lt;OptInInterestArea&gt;(
          (from a in _lstOptInInterest
           join b in _marketoEntities.CustCommPreferences.Where(tempQry)
           on new { CODE = a.Code, SUBCODE = a.SubCode } equals new { CODE = b.Option_Short_Name, SUBCODE = b.Option_Short_Subname }
           into leftGroup
           from b in leftGroup.DefaultIfEmpty()
           select new OptInInterestArea()
           {
               Code = a.Code,
               SubCode = a.SubCode,
               SubCodeDescription = a.SubCodeDescription,
               CodeDescription = a.CodeDescription,
               PrevOptIn = b != null &amp;&amp; b.OptedIn == true
           }).ToList());
  </code></pre>
  
  <p>It is giving compilation error <code>Where(tempQry)</code>. </p>
  
  <p><code>
  'System.Data.Entity.DbSet&lt;Market.Data.CustCommPreference&gt;' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Queryable.Where&lt;TSource&gt;(System.Linq.IQueryable&lt;TSource&gt;, System.Linq.Expressions.Expression&lt;System.Func&lt;TSource,bool&gt;&gt;)' has some invalid arguments</code></p>
  
  <p>How to handle this? </p>