0

I'm using Entity Framework 6 to map a Table with a "datetime" column mapped on a property like this "public System.DateTime DATAOPER { get; set; }"

This is the code first mapping:

this.Property(p => p.DATAOPER).HasColumnName("DATAOPER").HasColumnType("datetime").IsRequired();

I set the porperty with DateTime.Now but the INSERT statement generated is:

INSERT [dbo].[Tworkdom]([DATAOPER]) VALUES (@0)

parameter name: @0      parameter value: '13/12/2013 12:55:29'

It loses milliseconds information. I want instead a '13/12/2013 12:55:29.999' for example

1 Answers1

1

It's a mere display issue. If I create a table with two date columns, one with DateTime as (database) data type and one with DateTime2, I see this insert statement:

INSERT [dbo].[Users]([Inserted2], [Inserted])
VALUES (@0, @1)
...
-- @0: '13-12-2013 21:25:56' (Type = DateTime2)
-- @1: '13-12-2013 21:25:56' (Type = DateTime2)

However, the values in the database are:

Id          Inserted2                   Inserted
----------- --------------------------- -----------------------
1           2013-12-13 21:25:56.5023312 2013-12-13 21:25:56.503
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291