Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3976738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:50:25+00:00 2026-05-20T04:50:25+00:00

I have a Table in my DataBase (MS SQL 2008) with a default value

  • 0

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

The Idea is to automatically add Date and Time as soon as a new record is Created.

I create my Conceptual Model using EF4, and I have created an ASP.PAGE with a DetailsView Control in INSERT MODE.

My problems:

When I create a new Record. EF is not able to insert the actual Date and Time value but it inserts instead this value 0001-01-01 00:00:00.00.

I suppose the EF is not able to use SYSUTCDATETIME () defined in my DataBase

Any idea how to solve it? Thanks

Here 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 Temporary solution:
Please guys help me on this

e.Values[“DateCreated”] = DateTime.UtcNow;

More info here:

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

How to use the default Entity Framework and default date values

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:50:26+00:00Added an answer on May 20, 2026 at 4:50 am

    The problem is that EF doesn’t know about that default value so it sends .NET default value to database. It is possible to force EF to use default value from DB but you must manually modify EDMX file (XML not designer). You must find column definition in SSDL part of EDMX and add StoreGeneratedPattern=”Computed” attribute. You also must the same in CSDL part (this can be done in designer).

    This setting will have several problems. First of all each update from database will delete your changes in SSDL. Also each insert and update will trigger select which will requery value from this column (because EF thinks that it is computed every time).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in the database that I'm retrieving using LINQ to SQL,
In a SQL server database, I have a table which contains a TEXT field
I have a table in a SQL Server 2005 database with a trigger that
Lets say I have a table in a sql server 2000 database called TransactionType:
I have a SQL Mobile database with one table. It has several columns with
I have a database (NexusDB (supposedly SQL-92 compliant)) which contains and Item table, a
I have a field (say, foo) in a table in a SQL Server database
I'm helping implement a SQL Server 2008 database and I have several columns that
I am importing a table from one database to another in SQL Server 2008
I'm experiencing something a bit strange. I have a table on SQL Server 2008,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.