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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:18:26+00:00 2026-05-23T00:18:26+00:00

I have an ASP.NET MVC 3 Web Application using Linq-to-SQL for my data access

  • 0

I have an ASP.NET MVC 3 Web Application using Linq-to-SQL for my data access layer. I’m trying to increment a Views field every time the Details action is called, but I’m receiving a “Row not found or changed” error on db.SubmitChanges() if two people happen to hit the action at the same time.

public ActionResult Details(int id)
{
    DataClassesDataContext db = new DataClassesDataContext();

    var idea = db.Ideas.Where(i => i.IdeaPK == id).Single();

    idea.Views++;

    db.SubmitChanges();

    return View(new IdeaViewModel(idea));
}

I could set the UpdateCheck of the Views field to “Never” in my .dbml (Data Model), which would get rid of the error, but then the idea record could be updated twice with the same Views count. i.e.

First instance of Details action gets idea record with Views count of 1.
Second instance of Details action gets idea record with Views count of 1.
First instance increments Views to 2
First instance commits
Second instance increments Views to 2
Second instance commits

Result: Views field is 2 
Expected Result: Views field should be 3

I looked into using a TransactionScope, but I got the following deadlock error from one of the two calls:

Transaction (Process ID 54) was
deadlocked on lock resources with
another process and has been chosen as
the deadlock victim. Rerun the
transaction.

when I updated my action to look like:

public ActionResult Details(int id)
{
    DataClassesDataContext db = new DataClassesDataContext();

    using (var transaction = new TransactionScope()){
        var idea = db.Ideas.Where(i => i.IdeaPK == id).Single();

        idea.Views++;

        db.SubmitChanges();

        return View(new IdeaViewModel(idea));
    }
}

I also tried increasing the TransactionScope timeout using the TransactionScopeOptions and that didn’t seem to help (but I may have to set it elsewhere as well). I could probably solve this example by doing the increment in a single SQL command using db.ExecuteQuery, but I was trying to figure out how to make this work so I’ll know what to do in more complex scenarios (where I want to execute multiple commands in a single transaction).

  • 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-23T00:18:27+00:00Added an answer on May 23, 2026 at 12:18 am

    You should not need transactions or stored procedures. Just use DataContext.ExecuteCommand:

    db.ExecuteCommand("UPDATE Ideas SET Views = Views + 1 WHERE IdeaPK = {0}", id);
    

    This will execute it as one SQL statement, and is thus atomic.

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

Sidebar

Related Questions

I have an ASP.NET MVC application which is using Linq to SQL classes placed
I created one asp.net mvc application using linq to sql, and in the generated
I have an ASP.NET MVC Web Application that interacts with a SQL Server 2008
I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I'm developing an web application using asp.net MVC and jQuery. I have in my
I have a Silverlight project (with ASP.net MVC web project) Suddenly, when I press
Background I have a page on my ASP.NET MVC web app for users to
I have a standard ASP.NET MVC (RC Refresh) web project, with the standard ASP.NET
With ASP.NET MVC, it is common to have AJAX code(e.g. jQuery) to invoke web
I work on a web game , I use asp.net mvc, linqtosql. I have

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.