title: Having problems converting conditional where clause in LINQ back over to SQL
body: <p>I've got myself in a bit of a pickle!</p>
  
  <p>I've done a snazzy LINQ statement that does the job in my web app, but now I'd like to use this in a stored procedure:</p>
  
  <pre><code>var r = (from p in getautocompleteweightsproducts.tblWeights
                       where p.MemberId == memberid &amp;&amp;
                                p.LocationId == locationid
  
                       select p);
  
              if (level != "0")
                  r = r.Where(p =&gt; p.MaterialLevel == level);
  
              if (column == "UnitUserField1")
                  r = r.Where(p =&gt; p.UnitUserField1 == acitem);
  
              if (column == "UnitUserField2")
                  r = r.Where(p =&gt; p.UnitUserField2 == acitem);
  
  return r.OrderBy(p =&gt; p.LevelNo).ToList();
  </code></pre>
  
  <p>However, I can't for the life of me get the conditional where clause to work!!</p>
  
  <p>If someone can point me in the right direction, I'd be most grateful.</p>
  
  <p>Kind regards</p>