title: Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime' when inserting into Database using EFW and ViewModel
body: <p>I am working on this <code>ASP.NET Core MVC</code> project where I am trying to save the values from <code>form</code> into <code>Database</code> when I am getting this error: </p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>I have set <code>FromDate</code> and <code>ToDate</code> as <code>nullable</code> using <code>?</code> in the following way in the `ViewModel:</p>
  
  <p><strong>ViewModel:</strong></p>
  
  <pre><code>public class ILViewModel
  {
      ...
      ...
      public DateTime? FromDate { get; set; }
      public DateTime? ToDate { get; set; }
  }
  </code></pre>
  
  <p>In <code>Controller - POST Method</code>, I am adding values to the <code>Database</code> in the following manner: </p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>if (ModelState.IsValid)
  {
      ...
      historyObj.FromDate = locationsHistoryVM.FromDate;
      historyObj.ToDate = locationsHistoryVM.ToDate;
  }
  </code></pre>
  
  <p>What to do?</p>