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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:22:28+00:00 2026-06-12T00:22:28+00:00

I have models with datetime fields. My code is working with models setting this

  • 0

I have models with datetime fields.

My code is working with models setting this reseting this fields to now.
But I don’t want “setting” now, but “saving” now: i.e. if I set field1 = now [0:00:00], then, 10s. later field2 = now [0:00:10] and then, 10s. later, I execute SaveChanges() I’d like to have both field set to 0:00:20 (saving time).

Edit: code example:

var context = new SomeEntities();
SomeModel model = context.GetSomeModel(...);
// SomeModel has two DateTime fields: dt1 and dt2
model.dt1 = SavingDateTimeNow(); // .... 13:42:00
// some code, i.e. Sleep(TimeSpan.FromSeconds(10));
model.dt2 = SavingDateTimeNow(); // .... 13:42:10
// again 10s. code
context.SaveChanges(); // .... 13:42:20

Edit2: More complex example:

var context = new SomeEntities();
SomeModel model = context.GetSomeModel(...);
// SomeModel has two DateTime fields: dt1 and dt2
if(someComplexCondition)model.dt1 = SavingDateTimeNow(); // .... 13:42:00
// some code from which I would know if someOtherComplexCondition is true
if(someOtherComplexCondition)model.dt2 = SavingDateTimeNow(); // .... 13:42:10
// again 10s. code
// much more code here
context.SaveChanges(); // .... 13:42:20

I want both (dt1 and dt2) to be set to … 13:42:20, not 13:42:00 and 13:42:10

Edit3: Simplest example: I would like it to work just like django’s fields with auto_now=True.

  • 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-12T00:22:30+00:00Added an answer on June 12, 2026 at 12:22 am

    I found solution which isn’t perfect (if you find better one, please, post it here).
    Here is full article: Dave Dunkin’s blog: Automatic Timestamping for Entity Framework

    The idea is to:

    1. Create interface for models which needs this feature
    2. Implement infreface
    3. Create methods in Entitywhich would go through all modified entities, check for entitites implementng interface and modify its datetime fields (it could be done by method in this interface)
    4. Add this methods to SavingChanges event in Entity
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model with a datetime field: class MyModel(models.Model): created = models.DateTimeField(auto_now =
Dynamic Data question: I have 2 fields of type Nullable<DateTime> on my model When
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
Hello i'm working on a blog app and I have a model: class Post(models.Model):
Let's say I have a set of Django Models: class Article(models.Model): title = models.CharField(max_length=100,
The question here is similar, but I don't have any domain object inheritance. My
Imagine, I have News models with many text fields class News(models.Model): title = models.CharField(max_length=255)
I've followed this video series on WCF and have the demo working. It involves
I am working on form models and get this error: global name 'AdForm' is
I have a model like this: class Tour(models.Model): Name=models.CharField(max_length=100) Count=models.SmallIntegerField() ActionDate=models.DateTimeField(editable=False) ActionUser=models.ForeignKey(User,editable=False) StatusType=models.ForeignKey(StatusType) now

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.