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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:14:14+00:00 2026-05-14T05:14:14+00:00

I started working with linq to SQL several weeks ago. I got really tired

  • 0

I started working with linq to SQL several weeks ago. I got really tired of working with SQL server directly through the SQL queries (sqldatareader, sqlcommand and all this good stuff). 

After hearing about linq to SQL and mvc I quickly moved all my projects to these technologies. I expected linq to SQL work slower but it suprisongly turned out to be pretty fast, primarily because I always forgot to close my connections when using datareaders. Now I don’t have to worry about it.

But there’s one problem that really bothers me. There’s one page that’s requested thousands of times a day. The system gets data in the beginning, works with it and updates it. Primarily the updates are ++ @ — (increase and decrease values). I used to do it like this

UPDATE table SET value=value+1 WHERE ID=@I’d

It worked with no problems obviously. But with linq to SQL the data is taken in the beginning, moved to the class, changed and then saved.

Stats.registeredusers++;
Db.submitchanges();

Let’s say there were 100 000 users. Linq will say “let it be 100 001” instead of “let it be increased by 1”.

But if there value of users has already been increased (that happens in my site all the time) then linq will be like oops, this value is already 100 001. Whatever I’ll throw an exception”

You can change this behavior so that it won’t throw an exception but it still will not set the value to 100 002.

Like I said, it happened with me all the time. The stas value was increased twice a second on average. I simply had to rewrite this chunk of code with classic ado net.

So my question is how can you solve the problem with linq

  • 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-14T05:14:15+00:00Added an answer on May 14, 2026 at 5:14 am

    For these types of “write-only queries” I usually use a Stored Procedure. You can drag the stored procedure into the designer and execute it through the Linq to SQL DataContext class (it will be added as a method).

    Sorry for the trite answer but it really is that simple; no need to to finagle with raw ADO.NET SqlCommand objects and the like, just import the SP and you’re done. Or, if you want to go really ad-hoc, use the ExecuteCommand method, as in:

    context.ExecuteCommand("UPDATE table SET value = value + 1 WHERE ID = {0}", id);
    

    (But don’t overuse this, it can get difficult to maintain since the logic is no longer contained in your DataContext instance. And before anybody jumps on this claiming it to be a SQL injection vulnerability, please note that ExecuteCommand/ExecuteQuery are smart methods that turn this into a parameterized statement/query.)

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If your page relies on ViewState it's probably not a… May 14, 2026 at 5:27 am
  • Editorial Team
    Editorial Team added an answer Google app engine (Gae) does support XMPP just as CLIENT.… May 14, 2026 at 5:27 am
  • Editorial Team
    Editorial Team added an answer This: .h1color h1{ Should be: h1 .h1color { The order… May 14, 2026 at 5:27 am

Related Questions

I've just started working with ASP.NET MVC now that it's in beta. In my
OK, i have confirmed i only this issue when i attempt to query on
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
I know the topic I started is too subjective. But I just wanted some
I have started using Linq to SQL for a project im working on and

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.