title: Entity framework generates values for NOT NULL columns which has default defined in db
body: <p>Hi I have a table Customer. One of the columns in table is <code>DateCreated</code>. This column is <code>NOT NULL</code> but default values is defined for this column in db.</p>
  
  <p>When I add new <code>Customer</code> using EF4 from my code.</p>
  
  <pre><code>var customer = new Customer();
  customer.CustomerName = "Hello";                
  customer.Email = "hello@ello.com";
  // Watch out commented out.
  //customer.DateCreated = DateTime.Now;
  context.AddToCustomers(customer);
  context.SaveChanges();
  </code></pre>
  
  <p>Above code generates following query.</p>
  
  <pre><code>exec sp_executesql N'insert [dbo].[Customers]([CustomerName], 
  [Email], [Phone], [DateCreated], [DateUpdated])
  values (@0, @1, null, @2, null)
  select [CustomerId]
  from [dbo].[Customers]
  where @@ROWCOUNT &gt; 0 and [CustomerId] = scope_identity()
  ',N'@0 varchar(100),@1 varchar(100),@2 datetime2(7)
  ',@0='Hello',@1='hello@ello.com',@2='0001-01-01 00:00:00'
  </code></pre>
  
  <p>And throws following error</p>
  
  <pre><code>The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
  The statement has been terminated.
  </code></pre>
  
  <p>Can you please tell me how NOT NULL columns which has default values at db level should not have values generated by EF?</p>
  
  <p>DB:</p>
  
  <pre><code>DateCreated DATETIME NOT NULL
  </code></pre>
  
  <p>DateCreated Properties in EF:</p>
  
  <ul>
  <li><strong>Nullable:</strong> False</li>
  <li><strong>Getter/Setter:</strong> public</li>
  <li><strong>Type:</strong> DateTime</li>
  <li><strong>DefaultValue:</strong> None</li>
  </ul>
  
  <p>Thanks.</p>