title: Entity Framework setting datetime to null or min
body: <p>I'm using Entity Framework 5, Database First.</p>
  
  <p>I am doing something I've done many times before, but for some reason it is not working.</p>
  
  <p>My Table is defined as:
  </p>
  
  <pre><code>CREATE TABLE [dbo].[ActivationQueue](
  [ID] [int] IDENTITY(1,1) NOT NULL,
  [username] [nvarchar](255) NOT NULL,
  [email] [nvarchar](255) NOT NULL,
  [ActivationRequested] [datetime] NOT NULL,
  [ActivationEmailSent] [datetime] NOT NULL,
  [AccountActivated] [datetime] NOT NULL,
  [ActivationAttempts] [int] NULL,
  [ActivationKey] [uniqueidentifier] NULL,
  </code></pre>
  
  <p>CONSTRAINT [PK_Activations] PRIMARY KEY CLUSTERED </p>
  
  <p>This is the code I use to retrieve a particular row:
  </p>
  
  <pre><code>ActivationQueue accountActivation = DbSet.FirstOrDefault(a =&gt; a.username.ToLower() == userName)
  </code></pre>
  
  <p>When I use <code>DbSet.FirstOrDefault()</code> to get the first row, the ActivationEmailSent column is always returning <code>SQLDateTime.MinValue()</code> even though it has a correct value. The ActivationRequested column is always returning the correct value.</p>
  
  <p>I've used SQL profiler, and when I run the below SQL I get the correct <code>DateTime</code> value back.</p>
  
  <pre><code>exec sp_executesql N'SELECT TOP (1) 
  [Extent1].[ID] AS [ID], 
  [Extent1].[username] AS [username], 
  [Extent1].[email] AS [email], 
  [Extent1].[ActivationRequested] AS [ActivationRequested], 
  [Extent1].[ActivationEmailSent] AS [ActivationEmailSent], 
  [Extent1].[AccountActivated] AS [AccountActivated], 
  [Extent1].[ActivationAttempts] AS [ActivationAttempts], 
  [Extent1].[ActivationKey] AS [ActivationKey]
  FROM [dbo].[ActivationQueue] AS [Extent1]
  WHERE (LOWER([Extent1].[username])) = @p__linq__0',N'@p__linq__0         nvarchar(4000)',@p__linq__0=N'someusername'
  </code></pre>
  
  <p>The thing that gets me is that the mappings for the <code>ActivationRequested</code> and <code>ActivationEmailSent</code> are identical as are the definitions ( I just used <code>updateModel</code> in the edmx). But <code>ActivationRequested</code> returns the correct value, while <code>ActivationEmailSent</code> returns <code>SQLDateTime.Min</code> ( <code>1753-01-01 00:00:00.000</code> )</p>
  
  <p>I don't know whether this helps, but when I set the column to be nullable, it just returned null.</p>