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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:15:53+00:00 2026-06-10T17:15:53+00:00

Linq To SQL’s DataContext has an overload on SubmitChanges that allows for updates to

  • 0

Linq To SQL’s DataContext has an overload on SubmitChanges that allows for updates to continue when a Optimistic Concurrency Exception is thrown, and provides the developer with a mechanism to resolve the conflicts afterwards in a single Try Catch block.

Even the WCFDataServicesContext has a SaveChangedOptions.ContinueOnError parameter for its SaveChanges method that at least allows you to continue updating when an error has occurred and leaves conflicting updates unresolved so you can look into them later.

(1) Why then does the ObjectContext.SaveChanges method have no such option?

(2) Do any update patterns exist that will mimick the Linq To SQL behaviour? The examples I find on MSDN make it appear as if a single Try Catch block will see you home in the case of multiple updates. But this pattern does not allow you to investigate each conflicting update separately: it just alerts you to the first conflict and then gives you the option to “wipe the table clean in one sweep” to prevent any further optimistic concurrency exceptions from surfacing, without your knowing if any exist and what you would have liked to do about them.

  • 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-10T17:15:55+00:00Added an answer on June 10, 2026 at 5:15 pm

    Why then does the ObjectContext.SaveChanges method have no such option?

    I think the simplest answer is because Linq-to-Sql, Entity Framework and WCF Data Services were all implemented by different teams and internal communication among these teams doesn’t work as we would hope. I have described some interesting features missing in newer APIs in one of my former answers but I don’t think this is a missing feature – I will explain it in the second part of my answer.

    WCF Data Services have more interesting features which should be part of Entity framework as well. For example:

    • Change and Query interceptors
    • Batching multiple queries and SaveChanges operations to single call to server
    • Asynchronous operations – this will come to EF6 in form of async/await implementation

    Do any update patterns exist that will mimick the Linq To SQL behaviour?

    There is a pattern how to solve this but you will probably not like it. EF’s SaveChanges works as Unit of work. It either saves all changes or none. If you have a scenario where your saving operation can result in case where only part of your changes is persisted than it should not be handled by single SaveChanges call. Each atomic set of changes should have its own SaveChanges call:

    using (var scope = new TransactionScope(...)) {
        foreach (var entity in someEntitiesToModify) {
            try {
                context.SomeEntities.Attach(entity);
                context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
                context.SaveChanges();
            catch (OptimisticConcurrencyException e) {
                // Do something here 
    
                context.Refresh(e.StateEntries[0].Entity, RefreshMode.ClientWins);
                context.SaveChanges();
            }
        }
    
        scope.Complete();
    }
    

    I think the reason why this feature doesn’t exist is because it is not generic and as mentioned about it goes against unit of work pattern. Suppose this example:

    • You load an entity
    • You add a new dependent entity to navigation property of your loaded entity
    • You change something on the loaded entity
    • In the mean time somebody else concurrently delete your loaded entity
    • You trigger SaveChanges with relaxed conflict resolution
    • EF will try to save changes to the principal entity but it conflicts because there is no entity to update in the database
    • EF will continue because conflict resolution is relaxed
    • EF will try to insert dependent entity but it will fire SqlException because the principal entity doesn’t exist in the database. This exception will break the persistence operation and you will not know why it is complaining about referential integrity because you have a principal entity. (It is possible that this insert will even not happen and EF fires another exception due to inconsistency of context’s inner state but it depends on EF’s internal implementation).

    This immediately makes whole relaxing of conflict resolution much more complex feature. There are IMHO three ways to solve it:

    • Simply not support it. If you need conflict resolution per entity basis you can still use the example I showed above but for complex scenarios it may not work because complex scenarios are hard to solve.
    • Rebuild database change set each time the conflict occurs – it means to explore the remaining change set and exclude all entities related to conflicting entity and their relations an so on from the processed persistence. There is a problem: EF cannot exclude any changed entity from processing. That would break the meaning of unit of work and I repeat it one more: Relaxing conflict resolution can also break meaning of unit of work.
    • Let EF to proceed with dependencies even if the principal entity conflicted. This requires to handle the database exception and understand its content to know if the exception is fired due to conflicting principal or due to other error (which should fail whole persistence operation immediately). It can be quite difficult to understand database exceptions on the code level and moreover it is provider specific for every supported database.

    It doesn’t mean it may not be possible to make such functionality but it will need to cover all scenarios when it comes to relations and this can be pretty complex. I’m not sure if Linq-to-Sql handles this.

    You can always make a suggestion on Data UserVoice or check out the code and try to implement it yourselves. Maybe I see this feature too complicated and it can be implemented easily.

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

Sidebar

Related Questions

I have a linq-to-sql query that I use to fill an object that has
Linq to SQL has this very simple model: DataContext and attributes [Table] and [Column]
LINQ-to-SQL has been a PITA for me. We're using it to communicate to the
With LINQ to Sql, you can specify, for a given fetch, that you don't
The Linq to SQL Where extension method takes, as a parameter, something that looks
In LINQ to SQL, I get the exception The query operator 'ElementAt' is not
I've added a LINQ-SQL link in my website to make objects and after that,
Which layer is the best layer to make linq-sql calls as SubmitChanges(), InsertOnSubmit() etc.
I have a table Users.. it has a column ShowData using linq-sql how can
The Linq-To-SQL that needs refactoring is found below: var query = from p in

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.