The conversion of a datetime2 data type to a datetime data type RRS feed

  • Question

  • I have a field in my database with a DateTime datatype. Am also using EF4.1 fluent API to persist data into the database and am ending up getting this exceptions 

    {"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."}
    I know the easy way to fix this is to change the DataType in the database to datetime2(7) but my problem is I don't want EF to be changing datatype just because EF is asking me to do so. Nhibernate and Other ORM tools dont complain. Is there a way around this?

    Sunday, July 10, 2011 4:26 PM


  • Hi Edward,

    Welcome to the forum.


    The DateTime2 is a new type in the SQL2008 for more accurate.

    The entity framework 4 will convert the DateTime to DateTime2 by default.

    So Could you tell me the Version of your database, visual studio, and the type in your *.edmx

    For the solution:

    1、You can try to set the ProvidermanifestToken as 2005;

    2、You can try to assign the value as:

         From entity.CreateTime= new DateTime(2011,7,11,5,20,10,123);


    I hope that would be help you.


    Best Regards.



    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 3:46 AM