title: Trouble with checking for null in a SQL Compact query inside and MVC3 project
body: <p>I'm working through the SportsStore example from <a href="https://rads.stackoverflow.com/amzn/click/com/1430234040" rel="nofollow noreferrer" rel="nofollow noreferrer">Pro ASP.NET MVC 3 Framework</a>. At the beginning of chapter 8 i'm instructed to edit my ProductController class, adding the .Where line as follows:</p>
  
  <pre><code>    public ViewResult List(string category, int page = 1)
      {
          ProductsListViewModel viewModel = new ProductsListViewModel
          {
              Products = repository.Products
                  .Where(p =&gt; category == null || p.Category == category)
                  .OrderBy(p =&gt; p.ProductID)
                  .Skip((page - 1) * PageSize)
                  .Take(PageSize),
              PagingInfo = new PagingInfo
              {
                  CurrentPage = page,
                  ItemsPerPage = PageSize,
                  TotalItems = repository.Products.Count()
              },
              CurrentCategory = category
          };
          return View(viewModel);
      }
  </code></pre>
  
  <p>When I run the code i get the following error:</p>
  
  <pre><code>Exception Details: System.Data.SqlServerCe.SqlCeException: The specified argument
  value for the function is not valid. [ Argument # = 1,Name of
  function(if known) = isnull ]
  </code></pre>
  
  <p>on the foreach line in the following code block:</p>
  
  <pre><code>@model SportsStore.WebUI.Models.ProductsListViewModel
  
  @{
      ViewBag.Title = "Products";
  }
  
  @foreach (var p in Model.Products)
  {
      Html.RenderPartial("ProductSummary", p);
  }
  &lt;div class="pager"&gt;
      @Html.PageLinks(Model.PagingInfo, x =&gt; Url.Action("List", new {page = x}))
  &lt;/div&gt;
  </code></pre>
  
  <p>I've searched a good bit and found a lot of references to <a href="https://stackoverflow.com/questions/9188641/whats-is-wrong-with-this-linq-query">this StackOverflow post</a> in multiple places, but changing the query to</p>
  
  <pre><code>.Where(p =&gt; category == null ? true : p.Category == category)
  </code></pre>
  
  <p>had no effect.</p>
  
  <p>Some basic information:</p>
  
  <ul>
  <li>This is an MVC3 project using the Razer view engine and C#.</li>
  <li>All of the items in my SQL Compact 4.0 database have a category.</li>
  <li>Commenting out the category == null bit makes the code run just fine.</li>
  <li>The second version I gave above is what is in the downloadable source code from their site.</li>
  </ul>
  
  <p>It does work without the null checking, but i'm worried that if I just move on i may run into issues later on. Does anyone have any ideas as to how I can fix it?</p>