title: SqlDateTime overflow exception in Entity Framework
body: <p>When calling <code>context.SaveChange()</code>, I get an exception: <code>{"An error occurred while updating the entries. See the InnerException for details."}</code> with an InnerException of <code>"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."</code></p>
  
  <p>Generally this error is pretty easy to fix -- just find the DateTime property whose value was never set (defaulted to MinValue).  Unfortunately, I checked all properties on my object, and all of them are set to valid dates/times.</p>
  
  <p>Is there some way to figure out which property EF is referring to when throwing this exception?</p>
  
  <p>Also, I'm only actually checking the object I added to the context right before SaveChanges (and as far as I know, I'm only adding 1).  Is there a way to look at all pending data that is about to be saved?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>InnerException.StackTrace:</p>
  
  <pre><code>at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)
  at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)
  at System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb)
  at System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj)
  at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)
  at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
  at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
  at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
  at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
  at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
  at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>It may have to do something with my work flow... For example...</p>
  
  <ul>
  <li>I build object SalaryInformation in the class responsible for building Entity objects</li>
  <li>SalaryInformation has an Employee property on it, but the class that builds it only knows the Employee ID, so it sets SalaryInformation.Employee = new Employee { ID = 1 } (leaving the date fields set to MinValue)</li>
  <li>I pass the SalaryInformation object into a method to be saved</li>
  <li>Inside the save method, I look up the Employee object in the database based on the ID and then assign the returned Employee object to SalaryInformation.Employee</li>
  <li>I then <code>context.AddToSalaryInformation(SalaryInformation)</code> and <code>context.SaveChanges()</code></li>
  </ul>
  
  <p>I suspect this is leaving a straggler Employee behind in the context with only the ID set, and no Dates, thus the error.</p>
  
  <p><strong>Edit 3</strong></p>
  
  <p>Indeed, workflow was the issue.  If I simply say `SalaryInformation.Employee = null;' before assigning the employee object from the database, then the straggler goes away, and no error occurs.</p>
  
  <p>Is this the intended behavior and work around?  It seems quite terrible.</p>