title: LINQ to SQL Peculiarities
body: <p>I'm encountering some peculiarities with LINQ to SQL.</p>
  
  <p>With a relatively simple query, I want to select some fields, but have the date fields formatted as strings, which I first achieved like this:</p>
  
  <pre><code>        var list = dataContext.MyLists.Single(x =&gt; x.ID == myId);
  
          var items = from i in list.MyItems
                      select
                          new
                              {
                                  i.ID,
                                  i.Sector,
                                  i.Description,
                                  CompleteDate = i.CompleteDate.HasValue ? i.CompleteDate.Value.ToShortDateString() : "",
                                  DueDate = i.DueDate.HasValue ? i.DueDate.Value.ToShortDateString() : ""
                              };                               
  </code></pre>
  
  <p>Later on I tried the following query, which is exactly the same, except I'm querying straight from my dataContext, rather than an element in my first query:</p>
  
  <pre><code>        var items = from i in dataContext.MyLists
                      select
                          new
                              {
                                  i.ID,
                                  i.Sector,
                                  i.Description,
                                  CompleteDate = i.CompleteDate.HasValue ? i.CompleteDate.Value.ToShortDateString() : "",
                                  DueDate = i.DueDate.HasValue ? i.DueDate.Value.ToShortDateString() : ""
                              };
  </code></pre>
  
  <p>The first one runs fine, yet the second query yields a:                                </p>
  
  <p><em>Could not translate expression '...' into SQL and could not treat it as a local expression.</em></p>
  
  <p>If I remove the lines that Format the date, it works fine.  If I remove the .HasValue check it also works fine, until there are null values.</p>
  
  <p>Any ideas?</p>
  
  <p>Anthony</p>