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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:07:48+00:00 2026-05-22T22:07:48+00:00

The controller above has a standard edit ActionResult. I simply find rows in a

  • 0

The controller above has a standard edit ActionResult. I simply find rows in a database by ID and update it.
Before db.SaveChanges() there is log.Save() static function that saves all changes in model to separate tables in the database.
It simply check old and new values from ChangeTracker.
The problem is, i want use log.Save() after db.SaveChanges(), not before, to be sure that data was really saved.
But after, in the ChangeTracker there aren’t any changes so log.Save() doesn’t have anything to save.

Controller:

[HttpPost]
public ActionResult edit(int id, MyModel model)
{
  var hihi = db.MyModel.First(s => s.ID == model.ID);

  hihi.col1 = model.col1;
  hihi.col2 = model.col2;
  ...

  log.Save(Log.ChangeType.Edit, db, id);
      ^ Here i save changes to log.

  db.SaveChanges();


  return RedirectToAction("Index");
}

Log Class:

public void Save(ChangeType changeType, DBContext parentContext, int id)
{
  DBContext db = new DBContext();

  foreach (System.Data.Entity.Infrastructure.DbEntityEntry ee in parentContext.ChangeTracker.Entries())
  {
    foreach (string column in ee.OriginalValues.PropertyNames)
    {
      string oldValue = ee.OriginalValues[column].ToString();
      string newValue = ee.CurrentValues[column].ToString();

      if (oldValue != newValue)
      {
         var model = new LogModel
         {
            Log_Time = DateTime.Now,
            Log_Operator = User.Ope_ID,
            Log_Table = ee.Entity.ToString().Replace("xxx.Models.", ""),
            Log_Key = id,
            Log_Column = column,
            Log_Type = (int)changeType,
            Log_OldValue = oldValue,
            Log_NewValue = newValue
          };

          var log = db.Log.Add(model);
          db.SaveChanges();
        }
      }
   }
}

public enum ChangeType
{
  Create = 1,
  Delete = 2,
  Edit = 3
}

… or maybe someone has another way to save all changes in a database to another table on all controller actions, so after the project release I can see what users do.
PS. I don’t what user triggers.

  • 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-22T22:07:49+00:00Added an answer on May 22, 2026 at 10:07 pm

    SaveChanges in EF4 is virtual, so you can override it, add custom logging etc.

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

Sidebar

Related Questions

Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html
Several of my controller actions have a standard set of failure-handling behavior. In general,
I have a fairly standard blog app with the usual post and comments controller/models
This has been asked before by others, but I have not been able to
My controller has abstract base controller. I want to access the form post data
I have a controller that has a value that I want to pass to
I have a portlet which has many rendering and action methods: @Controller @RequestMapping(VIEW) public
I have an iPad app that has linear navigation with a Navigation Controller. I
I have a controller in an ASP.NET MVC application. The page has several filters
I do have my own Controller in Magento, that has been done by following

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.