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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:23:55+00:00 2026-06-10T15:23:55+00:00

I’m building some sort of an auditing behavior in an MVC3 app with EF,

  • 0

I’m building some sort of an auditing behavior in an MVC3 app with EF, and I’ve tried several approaches, trying to avoid high impacts on the code, and, of course, trying to avoid as much extra code as I can, since the application is at 35-ish % done.

Audit object looks like this:

  • AuditId
  • UserId
  • OperationId
  • ModuleId
  • Timestamp
  • Payload
  • < Module >
  • < Operation >
  • < User >

The idea goes as follows:

I’ve created a partial class to hide the SaveChanges() and override SaveChanges(SaveOptions).

Then I’ve created two more overloads of the same method to receive my entity as a parameter and/or not a SaveOptions enum parameter.

The new SaveChanges() besides the obvious, sets the properties of my Audit entity, but the problem takes place here: I need a User, Module and an Operation.

My current solution to solve this is the following:

  • I’ve declared an Audit object at the constructor class level.
  • In the controller’s constructor I set the User to my Audit object.
  • In each method I set the Operation as needed.
  • In the save changes I process the payload (an xml in my case) from the ObjectStateManager.

I'm very skeptic about this approach, it seems to be a little intrusive to my code. I've read lots of posts here in SO, but none of them helped me to improve this approach nor decide to change it. So please avoid linking things I've probably already read.

  • 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-10T15:23:57+00:00Added an answer on June 10, 2026 at 3:23 pm

    Another option is to decorate your database entities you wish to audit with a custom attribute. Check for the attribute during SaveChanges. For the module and operation fields, you can capture the stack trace at that time – find the calling controller and action from that. This would help keep your controllers cleaner.

    I do audits at a column level, not obejct. Typically I only care about a few columns, not the entire thing. For reference, here’s my base DbContext. I subscribe to the the ObjectContext.SavingChanges event, check everything marked as modified, and then for any properties with a custom [Audit] attribute. This could easily be expanded to also check for deletions.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.