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 8678865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:49:48+00:00 2026-06-12T20:49:48+00:00

I want to apply a timestamp to my Entity Framework project. I have a

  • 0

I want to apply a timestamp to my Entity Framework project. I have a class listed below. I hoped that this class would grab the current DateTime. But instead it provides me a field to enter my datetime. I want this to grab the current datetime.

 public class Answer
    {
        public int ID { get; set; }
        public string Answers {get; set;}
        public System.DateTime DateCreated { get; set; }
        public string Division { get; set; }
        public string Phone { get; set; }
        public string Description { get; set; }



    }

Below is the line of code that i know is wrong.

public System.DateTime DateCreated { get; set; }

i am a little unsure of how to go about this. I am new to entity and new to MVC. Any help would be greatly appreciated.

  • 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-06-12T20:49:49+00:00Added an answer on June 12, 2026 at 8:49 pm

    You could initialize it in the constructor e.g.

    public class Answer
    {
        public Answer()
        {
            DateCreated = DateTime.UtcNow;
        }
    
        ...
    }
    

    However, I get the impression that your Answer class isn’t actually an entity but a view model. For actual entities, what I tend to do with fixed/generated values like this is let the database populate the field with a default value e.g. GetUtcDate() and then in the EF designer set the StoreGeneratedPattern property to Computed – that way when you pull down your entities the CreatedDate will be pre-populated. This gives you data integrity both ways as you won’t be able to overwrite the field in the database either when pushing your data back up.

    Then it’s just a case of mapping your Answer entity to your Answer view model therefore nothing has to be initialized.

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

Sidebar

Related Questions

i have this elements <div class="a b"></div> <div class="b"></div> <div class="a"></div> I want apply
i want to apply for this job as description below: This employer is looking
I want apply margin property for my html newsletter But Gmail ignores this CSS
i want to apply masking over the textinput that need to get SSN from
I want to apply a Storyboard to my Rectangle Fill like this: <Rectangle Name=MyRectangle
I want to apply cycle to the div block with dynamic content. This content
If a href is longer than 40 chars I want apply a class to
I want to apply a XSL style sheet that delete duplicate nodes in my
I want to apply a class 'solo' to a link in a paragraph where
I have a table where i want to apply some aggregation functions having as

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.