title: Converting DateTime to String Entity Framework
body: <p>I have the following code, trying to return d.dateofbirth and d.dateofdeath as strings without much luck.</p>
  
  <p>I have tried using tostring() or convert but both are converted to sql during the runtime so therefore don't work,</p>
  
  <p>I need to be able to show DOB and DOD on 2 lines in the same gridview cell, like this:</p>
  
  <p>DOB
  DOD</p>
  
  <p>Heres my code so far:</p>
  
  <pre><code>fmsEntities context = new fmsEntities();
  var query = from f in context.funerals
              where f.IsPencil == 0
              join d in context.deceaseddetails on f.DeceasedID equals d.ID
              join i in context.funeralservices on f.ID equals i.FuneralID
              where i.IsAlternative == 0
              join h in context.htvalues on f.HtValuesID equals h.ID
              join p in context.placeofdeaths on f.PlaceOfDeathID equals p.ID
              join c in context.coroners on f.CoronerID equals c.ID
              select new DataBindingProjection { DeceasedName = (d.LastName + Environment.NewLine + d.FirstName),
              DOBDOD = Convert.ToString(d.DateOfBirth)};
  
  var dataobjects = query.ToList();
  
  dataGridView1.DataSource = dataobjects;
  </code></pre>
  
  
  
  <pre><code>private class DataBindingProjection
  {
      public string DeceasedName {get; set;}
      public string DOBDOD {get; set;}
  }
  </code></pre>
  
  <p>Update, Moved ToList before building the dataProjection as recommended in comments,</p>
  
  <pre><code>fmsEntities context = new fmsEntities();
          var query = (from f in context.funerals
                      where f.IsPencil == 0
                      join d in context.deceaseddetails on f.DeceasedID equals d.ID
                      join i in context.funeralservices on f.ID equals i.FuneralID
                      where i.IsAlternative == 0
                      join h in context.htvalues on f.HtValuesID equals h.ID
                      join p in context.placeofdeaths on f.PlaceOfDeathID equals p.ID
                      join c in context.coroners on f.CoronerID equals c.ID
                      select new { f , d , i , h , p , c }).ToList();
  
          var dataobjects = query.Select(d =&gt; new DataBindingProjection {DeceasedName = (d.LastName + Environment.NewLine + d.FirstName),
                                          DOBDOD = (d.DateOfBirth.ToString() + Environment.NewLine + d.DateOfDeath.ToString())});
  
          dataGridView1.DataSource = dataobjects;
      }
  
      private class DataBindingProjection
      {
          public string DeceasedName {get; set;}
          public string DOBDOD {get; set;}
      }
  </code></pre>