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

  • Home
  • SEARCH
  • 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 560753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:22:37+00:00 2026-05-13T12:22:37+00:00

Based on this link it looks like I can get date inserted / date

  • 0

Based on this link it looks like I can get date inserted / date modified information “for free” (without the need for triggers etc.) using Sql Server 2008 by simply enabling Change Tracking. I am using Entity Framework to access the data. My question is, how do I access date modified / date inserted information for the database records via Entity Framework and LINQ?
I’m using VS2008 so I don’t have the new EF v4 stuff yet (but if it can be done in the new EF please let me know).
Thanks.

  • 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-13T12:22:38+00:00Added an answer on May 13, 2026 at 12:22 pm

    OK, this works beautifully (also see this article)…

    public partial class MyEntities
    {
        partial void OnContextCreated()
        {
            this.SavingChanges += new System.EventHandler(CustomSavingChangesLogic);
        }
    
        /// <summary>
        /// Apply timestamps
        /// </summary>
        public void CustomSavingChangesLogic(object sender, System.EventArgs e)
        {
            var changedEntities = ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified);
            foreach (var stateEntryEntity in changedEntities)
            {
                if(!stateEntryEntity.IsRelationship) {
                    var entity = stateEntryEntity.Entity;
                    var lastModifiedPropInfo = entity.GetType().GetProperty("LastModified");
                    if (lastModifiedPropInfo != null)
                        lastModifiedPropInfo.SetValue(entity, DateTime.UtcNow, null);
                    if (stateEntryEntity.State == EntityState.Added)
                    {
                        var createdPropInfo = entity.GetType().GetProperty("Created");
                        if (createdPropInfo != null)
                            createdPropInfo.SetValue(entity, DateTime.UtcNow, null);
                    }
    
                }
            }
        } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This request is based in MS Access VBA. I would like to know what
By this, I don't mean PC-based development environments (like Visual Studio) for developing and
I have sitemap which looks like this: <?xml version=1.0 encoding=utf-8 ?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 >
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for
I want to create dynamic content based on this. I know it's somewhere, as
I have up to 4 files based on this structure (note the prefixes are
I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
Based on the response to this question: Why does C++ have header files and

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.