Convert Datetime2 to EF4

Well, having spent endless time searching for an answer, I have to add another question in this question ...

I have a table with 2 datetime fields created by EF4 EDMX designer in VS 2010.

the generated fields in SQL 2008 are datetime, not datetime2.

looking at edmx markup, the fields are of type datetime2.

the insertion does not work with the known datetime2 / datetime conversion problem ....

I manually changed the fields to datetime2 in the sql table.

still no luck.

I probably missed something, but I can not understand what is happening.

I even tried to restore db from the designer and recreate edmx from db ...

still the same problem.

any help greatly appreciated.

+6
entity-framework-4 datetime2 designer edmx
source share
2 answers

I had a similar problem caused by creating a model with SQL Server 2005 and then trying to access using SQL Server 2008. I fixed this by editing the edmx file with notepad ++ or an equivalent change from 2005 to 2008 in the next 2nd edmx file line:

<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"> 

Another thing: delete the table in edmx and right-click "Update Model from Database" to re-add it with the desired data type this time.

0
source share

One solution to this problem is to ensure that the date and time are correctly initialized in your entities. Datetime is a structure, by default it will be initialized to 0.

I was looking for this a bit.

0
source share

All Articles