title: How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer?
body: <p>I'm using the DbContext and Code First APIs introduced with Entity Framework 4.1.</p>
  
  <p>The <strong>data model</strong> uses basic data types such as <code>string</code> and <code>DateTime</code>. The only data annotation I'm using in some cases is <code>[Required]</code>, but that's not on any of the <code>DateTime</code> properties. Example:</p>
  
  <pre><code>public virtual DateTime Start { get; set; }
  </code></pre>
  
  <p>The <strong>DbContext subclass</strong> is also simple and looks like:</p>
  
  <pre><code>public class EventsContext : DbContext
  {
      public DbSet&lt;Event&gt; Events { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Event&gt;().ToTable("Events");
      }
  }
  </code></pre>
  
  <p>The <strong>initializer</strong> sets dates in the model to sensible values in either this year or next year.</p>
  
  <p>However when I run the initializer, I get this error at <code>context.SaveChanges()</code>:</p>
  
  <blockquote>
    <p>The conversion of a datetime2 data
    type to a datetime data type resulted
    in an out-of-range value. The
    statement has been terminated.</p>
  </blockquote>
  
  <p>I don't understand why this is happening at all because everything is so simple. I'm also not sure how to fix it since there is no edmx file to edit.</p>
  
  <p>Any ideas?</p>