title: Using Contains() on an IQueryable built with Dapper (with MVCContrib Grid)
body: <p>I've got the following ActionResult in a ASP.NET MVC 3 project:</p>
  
  <pre><code>public ActionResult Index(string searchWord, GridSortOptions gridSortOptions, int? page)
  {
      var userListModel = new PagedViewModel&lt;UserModel&gt;
      {
          ViewData = ViewData,
          Query = conn.Query&lt;UserModel&gt;("select Id, Login, Firstname, Lastname from User").AsQueryable(),
          GridSortOptions = gridSortOptions,
          DefaultSortColumn = "Id",
          Page = page,
          PageSize = 20
      }
      .AddFilter("searchWord", searchWord, u =&gt; u.Login.Contains(searchWord) || u.Firstname.Contains(searchWord) || u.Lastname.Contains(searchWord))
      .Setup();
  
      return View(userListModel);
  }
  </code></pre>
  
  <ul>
  <li>The GridSortOptions and PagedViewModel classes are from MVCContrib as the view is using
  the Grid from MVCContrib to display the data.</li>
  <li>conn is a standard SQLConnection talking to a SQL server database.</li>
  <li>conn.Query is a SQLConnection extension method provided by Dapper which I'm using to get the data.</li>
  <li>The Query property being filled in the PagedViewModel is a IQueryable type</li>
  </ul>
  
  <p>If searchWord is null all works fine, but as soon as you add a searchWord the MVCContrib Grid falls over with an 'Object reference not set to an instance of an object' error. It works if I remove the .Contains) from the AddFilter method like this:</p>
  
  <pre><code>.AddFilter("searchWord", searchWord, u =&gt; u.Login == searchWord)
  </code></pre>
  
  <p>Anyone know a way around this, or why I can't use Contains with the Dapper IQueryable?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Thanks to Sam's answer this fixes it:</p>
  
  <pre><code>.AddFilter("searchWord", searchWord, u =&gt; (!string.IsNullOrEmpty(u.Login) &amp;&amp; u.Login.Contains(searchWord))
  </code></pre>