Entity Framework 4 and SYSUTCDATETIME ()

I have a table in my database (MS SQL 2008) with a default value for a column SYSUTCDATETIME ().

The idea is to automatically add the date and time as soon as a new record is created.

I create my conceptual model using EF4, and I created ASP.PAGE with the DetailsView control in INSERT MODE.

My problems:

When I create a new record. EF cannot insert the actual "Date and Time" value, but instead enters this value 0001-01-01 00: 00: 00.00.

I believe EF cannot use SYSUTCDATETIME () defined in my database

Any idea how to solve it? Thanks

Here is my SQL script

    CREATE TABLE dbo.CmsAdvertisers
(
    AdvertiserId            int             NOT NULL    IDENTITY
        CONSTRAINT PK_CmsAdvertisers_AdvertiserId PRIMARY KEY,
    DateCreated             dateTime2(2)    NOT NULL
        CONSTRAINT DF_CmsAdvertisers_DateCreated DEFAULT sysutcdatetime (),
    ReferenceAdvertiser     varchar(64)     NOT NULL,
    NoteInternal            nvarchar(256)   NOT NULL
        CONSTRAINT DF_CmsAdvertisers_NoteInternal DEFAULT ''
);

My workaround: Please guys help me on this

e.Values ​​[ "DateCreated" ] = DateTime.UtcNow;

:

http://msdn.microsoft.com/en-us/library/bb387157.aspx

Entity Framework

http://msdn.microsoft.com/en-us/library/dd296755.aspx

+3
2

, EF , .NET . EF , EDMX (XML not designer). SSDL EDMX StoreGeneratedPattern = "Computed". CSDL ( ).

. , SSDL. , ( EF , ).

+1

ASP.NET DateCreated. , , , .

, , , , DateCreated. a DateTime 0001-01-01 00:00:00.00, .

, , , DateCreated. , EF, ( , ).

, , EF , .

+1

Source: https://habr.com/ru/post/1793612/


All Articles