title: C# - Parsing Data inside Lambda Linq Block | Splitting .Where()
body: <p>I want to filter Entities from a Database, but I am kinda stuck on how to correctly chain the Methods together....</p>
  <p>The User can search from one Textfield the Id, Title and Description. This SearchString will be bound to SearchString in SearchData.</p>
  <p>I have a method:</p>
  <pre class="lang-cs prettyprint-override"><code>public List&lt;Movies&gt; Search(SearchData search)
  {
      var movies = from m in entities select m;
      if (!String.isNullOrEmpty(search.SearchString))
      {
          movies = movies.Where(x =&gt; x.Title.Contains(search.SearchString)).Where(//descritpion);
      }
      return movies;
  }
  </code></pre>
  <p>This works, but I also need to check for the Id</p>
  <pre><code>.Where(x=&gt;x.Id == search.SearchString)
  </code></pre>
  <p>This won´t work since Id is a int and SearchString a String.</p>
  <p>I have tried multiple ways to do so:
  I did use &quot;Convert.ToInt32&quot; on the SearchString or &quot;Convert.ToString&quot; on the Id, but out of some reason I won´t get anything back with this and an Error when I search for a String.</p>
  <p>I tried to use a block with in the where : .Where(x =&gt; {if(Tryparse(Searchstring) {}else{}}), but it doesn´t like it when I try to return the Movie object or null.</p>
  <p>I also tried to split the clause up:</p>
  <pre class="lang-cs prettyprint-override"><code>if (int.tryparse(searchstring)) 
      movies = movies.where(x=&gt;x.id ==Int32.Parse(SearchString));
  movies = movies.where(//title and desc)
  </code></pre>
  <p>,but with this all the Movies I have found in the if will be filtered out due to the title and desc.</p>
  <p>My questions are:</p>
  <p>1.)Is it possible to &quot;split&quot; those Methods so that they behave like an OR instead of an AND?.... Or that they will not be executed anymore after one worked since the User will only be allowed to enter an Int OR a String. I have more values I am filtering against for which I would need this too.</p>
  <p>2)How can I test against more &quot;complex&quot; Logic inside the Lambdas?</p>