I have an EF4 EDM called UnitHistoryEntities
. The database is stored in SQL Express 2012. Windows 7 64-bit.
context = new UnitHistoryEntities()
.var unit = new Unit()
, set a few properties, and add it to the context with context.Units.AddObject(unit)
context.SaveChanges()
.The call to SaveChanges()
never, ever returns (I've given it at least 10 minutes) and never throws an exception. If I remove the AddObject()
, it returns without making any changes to the database, because nothing was modified.
Why does SaveChanges()
never return? Anyone experience this phenomenon?
I am able to connect and perform queries on the database from SQL Management Studio while my program is in this condition.
Turns out the problem I'm having is very similar to this question. I have a DateTime field that I was not setting. I made a console app that performed exactly the same actions on the context that my application was doing. In this case, SaveChanges()
did return, with the exception The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated.
So I now set my DateTime field to 1/1/1900 and I'll treat that like a null date. My program now operates properly.
Strange that I didn't get an exception thrown in my WPF application, but I did in the console application...