6

well, after having spent endless time googling for an answer , i have to add another question in this matter...

i have a table with 2 datetime fields, generated by EF4 EDMX designer in VS 2010.

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

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

the insert is failing with the known conversion issue datetime2 / datetime....

i have manually changed the fields to datetime2 on the sql table.

still no luck.

i am probably missing something here but can't figure out what the heck is going on.

i even tried regenerating the db from the designer and recreating the edmx from the db...

still the same issue.

any help is greatly apreciated.

user300435
  • 95
  • 5
  • 1
    Create edmx model of the database in a separated console application and try insert there. (Add New Item, Entity Data Model, From Database). If it works - delete a necessary table in working edmx and update model. It allways works for me. – vortexwolf Nov 23 '10 at 20:00

2 Answers2

0

I had a similar issue once caused by creating the model from SQL server 2005 and then trying to access using SQL server 2008. I fixed this by editing the edmx file using notepad++ or equivalent changing the 2005 to 2008 in the following 2nd line of the edmx file:

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

The other thing to try is deleting the table in the edmx and right click Update Model From Database to re-add it hopefully with the right data type this time round.

Chris Snowden
  • 4,982
  • 1
  • 25
  • 34
0

One solution to this problem is to make sure that you correctly initialize the datetime in your entities. Datetime is a struct, it will be initialized to 0 by default.

I did search for that one a little while.

Vincent Hubert
  • 1,386
  • 9
  • 23