title: DbComparisonExpression requires arguments with comparable types
body: <p>I'm new to using Linq and am trying to create a search that will search by chart number and display the results in a new action view. When running the code I get the error "DbComparisonExpression requires arguments with comparable types".  I believe this has something to do with the search type being string and chart number being int, but I'm not sure how to fix the problem.  Any help would be greatly appreciated!</p>
  
  <p><strong><em>Controller:</em></strong></p>
  
  <pre><code>public ActionResult Index(string searchTerm = null)
  {
      var model =
          db.Patient
          .Where(r =&gt; searchTerm == null || r.ChartNumber.Equals(searchTerm))
                  .Select(r =&gt; new NewListModel
                  {
                      ChartNumber = r.ChartNumber,
                      FirstName = r.FirstName,
                      LastName = r.LastName,
                  }
                  );
      return View(model);
  }
  </code></pre>
  
  <p><strong><em>Model:</em></strong></p>
  
  <pre><code>public class NewListModel
  {
      public int ChartNumber { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
  
  }
  </code></pre>
  
  <p><strong><em>View:</em></strong></p>
  
  <pre><code>@model IEnumerable&lt;Project.Models.NewListModel&gt;
  @{
      ViewBag.Title = "Home Page";
  }
  
  &lt;form method="get"&gt;
      &lt;input type="search" name="searchTerm" /&gt;
      &lt;input type="submit" value="Search by Chart Number" /&gt;
  &lt;/form&gt;
  
  @foreach (var item in Model)
  {
      &lt;div&gt;
          &lt;h4&gt;@item.ChartNumber&lt;/h4&gt;
  
      &lt;/div&gt;
      &lt;div&gt;@item.FirstName&lt;/div&gt;
      &lt;div&gt;@item.LastName&lt;/div&gt;
  
  }
  </code></pre>
  
  <p>New controller </p>
  
  <pre><code>public ActionResult Index(string searchTerm = null)
          {
              int chartNo;
              if (searchTerm == null || Int32.TryParse(searchTerm, out chartNo)) {
              var model = db.Patient
              .Where(r =&gt; searchTerm == null || r.ChartNumber == chartNo)
              .Select(r =&gt; new NewListModel
                  {
                      ChartNumber = r.ChartNumber,
                      FirstName = r.FirstName,
                      LastName = r.LastName,
                  }
                  );
               return View(model);
              } else {
                  //Invalid number entered 
              }
              }
  </code></pre>