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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:01:06+00:00 2026-06-10T20:01:06+00:00

I need to track a change history of some database objects in a MVC

  • 0

I need to track a change history of some database objects in a MVC .NET application using the code first approach.

Here is what is meant by history table:
http://database-programmer.blogspot.de/2008/07/history-tables.html

I would use a history table for it, if I would write the SQL queries myself. But in the code first approach the SQL is generated… and I would like to stick to this paradigm.

The goal is a structure that holds all “old” revisions of changed/deleted entries together with some additional information (e.g. timestamp, user who changed it, …)

Any ideas?

Regards,
Stefan

To be more specific – here is some code example:

public class Node {
 public int NodeID { get; set; }

 public string? data { get; set; }  // sample data
}


public class NodeHistory {
  public int NodeID { get; set; }
  public string? data { get; set; }

  public int UserID { get; set; }
  public DataTime timestamp { get; set; }
}

What I need is some “framework” assistance to be able to add an entry to NodeHistory whenever a change is -persisted- to table the Node structure.

That means: Just overriding the set-method isn’t a solution, as it would also create an entry, if the change to a “Node” is not persisted at the end (e.g. roleback).

  • 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-10T20:01:08+00:00Added an answer on June 10, 2026 at 8:01 pm

    I think the best approach for me would be to use a repository pattern and do the insertion into the NodeHistory table on every operation on the Node object that you see fit to keep a history of.

    EDIT: Some code

    public class NodeRepository{
        public Node EditNode(Node toEdit, int userId){
            using(new TransactionScope())
            {            
                //Edit Node in NodeContext like you would anyway without repository
                NodeContext.NodeHistories.Add(new NodeHistory(){//initialise NodeHistory stuff here)
                NodeContext.SaveChagnes();
            }
        }
    }
    public class NodeContext:DbContext{
        public DbSet<Node> Nodes{get;set;}
        public DbSet<NodeHistory> NodeHistories{get;set;}
    }
    

    If you are looking for something simpler than this, then I have no idea what it might be.

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

Sidebar

Related Questions

I have a <select> element which I need to track using change(). jQuery('.dropdown').change(function(){ yada,
I'm currently working on an ASP.NET MVC project using NHibernate and I need to
I have some code (which I cannot change) that I need to get working
I need to Track Unique Visitor count in my web application. I would really
For my application I need to keep track of all files that are touched
I need to track changes created in a directory and also saved the history.
Here is the situation: I have a database of 'tickets', and we track changes
I'm using JQuery Sortable UI Where I need to track current position array of
I need to track outbound clicks from a directory on our site, and would
I am receiving a stream of unordered Int32 values and need to track the

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.