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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:48:33+00:00 2026-05-14T00:48:33+00:00

We use queries generated by Linq for data retrieval but for INSERT and UPDATE

  • 0

We use queries generated by Linq for data retrieval but for INSERT and UPDATE we do not allow generated SQL, but restrict to the use of stored procedures.

I connected the Update and the Insert behaviour in the DBML to the stored procedures.
The procedures are called, the data gets inserted/updated = all if fine, except in the case of optimistic concurrency.

If a record was changed between retrieval and update, the update should fail.

When Linq generates the Update statement itself, it throws a ChangeConflictException as expected, but using the stored procedure no Exception is thrown.

Thanks a lot for any help on this!

  • 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-14T00:48:33+00:00Added an answer on May 14, 2026 at 12:48 am

    When configuring the UPDATE behavior to use the update stored procedure, Linq2SQL generates a method that is not throwing concurrency exceptions.
    To handle optimistic concurrency I found a proposed solution in the MSDN forums

    You can implement the Update method yourself in the patial DataContext class and throw a ChangeConflictException.

    To achieve this you have to:

    • write an Update stored procedure which takes the current and original values as parameters
      • using WHERE columnA = OriginalValueA ... to update only if the values were not changed
      • the last line in the stored procedure is RETURN @@ROWCOUNT
      • the rowcount lets you see if the row was updated or not
    • in the DBML set the Update behaviour to “use runtime”
    • the partial class xxxDataContext implement an Update method like this:
      • the code is taken from what Linq2SQL generates, just the last line to throw the exception is added
    partial void UpdateYourEntityClass(YourEntityClass obj)
            {
                EntityClass original = ((YourEntityClass)(EntityClasss.GetOriginalEntityState(obj)));
                int result = this.YourEntityClassUpdate((...));
                if (result == 0) throw new ChangeConflictException();
            }
    

    Working, but not straight forward.
    Any other options?

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

Sidebar

Ask A Question

Stats

  • Questions 462k
  • Answers 462k
  • 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 This is because Firefox doesn't natively support WMV, whereas IE… May 16, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer It's not an assembly, it's a COM component. Project +… May 16, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer If some email is getting through, it is probably not… May 16, 2026 at 12:27 am

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.