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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:38:24+00:00 2026-05-11T20:38:24+00:00

I am trying to implement Optimistic Locking in an asp.net MVC application, as well

  • 0

I am trying to implement Optimistic Locking in an asp.net MVC application, as well as provide audit trailing.

The audit framework relies on being able to call DataContext.GetModifiedMembers during SubmitChanges, which makes good sense, i guess.

The optimistic locking uses ROWVERSION timestamps, serialized to base64 and put in a hidden field in the view.

My Edit action looks like this:

[AcceptVerb(HttpVerb.Post)] 
public ActionResult Edit(MyType myType)
{ 
   context.MyTypes.Attach(myType, true);
   context.SubmitChanges(ConflictMode.FailOnFirstConflict);
}

When doing this, the DataContext.GetModifiedMembers will always return ALL the properties on MyType, rather than just the ones that are changed between the database and the values provided, which breaks the auditing.
Specifically it returns every property as having been changed from their new value to their new value, so its not even like I can do anything clever to the list.

I tried loading the object first, before attaching it, but this gives a duplicate key exception.

I then tried using UpdateModel, i.e.

[AcceptVerb(HttpVerb.Post)] 
public ActionResult Edit(int id, FormCollection col)
{ 
   var mt = context.MyTypes.Single( mt =>  mt.id = id);
   UpdateModel(mt);
   context.SubmitChanges(ConflictMode.FailOnFirstConflict);
}

This works with the auditing, but fails the optimistic locking.
Rather than a ChangeConflictException i get an InvalidOperationException because the UpdateModel is changing the concurrentTS field (which apparently is readonly).

What am I doing wrong?

  • 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-11T20:38:24+00:00Added an answer on May 11, 2026 at 8:38 pm

    Progress so far consists of doing the last part, and catching InvalidOperationException and looking for the text “Value of member ‘ConcurrencyTimestamp'”, and rethrowing that as a ChangeConflictException.

    That seems to do the trick, but it is not pretty.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use command line switches on regedit.exe to read/write… May 12, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer Which autocomplete plugin are you using? I use the one… May 12, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer you can do xpathcount = selenium.getXpathCount("//input"); for (i = 0;i<xpathcount;i+=1){… May 12, 2026 at 12:51 am

Related Questions

I am trying to implement string unescaping with Python regex and backreferences, and it
I am trying to implement a software Null Modem . Any suggestion how to
I am trying to implement AJAX in my Google App Engine application, and so
I am trying to implement a request to an unreliable server. The request is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.