Reputation: 3620
Im getting a strange error when trying to add a new item to a table using LINQ
error : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Code:
dbc.TblEvent newEvent = new dbc.TblEvent();
newEvent.Subject = "Registered";
newEvent.PersonID = PersonId;
newEvent.EventDate = DateTime.Now;
newEvent.EventTypeID = 23;
newEvent.EventStatusID = 10;
context.TblEvents.InsertOnSubmit(newEvent);
As you can see I'm not doing anything exciting. What can I do to sort this?
Upvotes: 1
Views: 3916
Reputation: 2915
Another scenario for this: changed a query from a LEFT JOIN to an INNER JOIN, hence making a previously nullable datetime field, non-nullable. Needed to delete the table from the .dbml and re-add to get his to refresh the model.
Upvotes: 0
Reputation: 1248
99 out of 100 times a date time overflow in linq happens because the date is not being set. DateTime has a default value that is lower than the lowest date sql can handle.
Check all your assignments. Are you missing another date time field in your table?
Upvotes: 5