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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:34:24+00:00 2026-06-08T17:34:24+00:00

I am currently running an app with a very LONG Linq transaction. Everything has

  • 0

I am currently running an app with a very LONG Linq transaction. Everything has to happen in this one transaction, and I’m not sure if or where objects are interfering with each other.

When I try to save the changes I see this warning come up:

System.InvalidOperationException: The changes to the database were
committed successfully, but an error occurred while updating the
object context. The ObjectContext might be in an inconsistent state.
Inner exception message: AcceptChanges cannot continue because the
object’s key values conflict with another object in the
ObjectStateManager. Make sure that t he key values are unique before
calling AcceptChanges.

From what I’ve read googling around, people have found a lot of one-off solutions (rarely having anything to do with conflicting keys), and they don’t usually post what the tip-offs are (better than nothing, of course).

What I’m not clear on is how do I hunt down the cause of this problem?

I update a lot of records in different places and let them go out of scope. I’m guessing the .NET compiler knows how to keep track of these objects without letting them go through the GC so it can commit everything at the end. And all the changes seem to end up in the database afterword.

Example:

            // create new A, SA for new incoming tasks
            SF_SUB_AREA sa = null;
            SF_AREA a = null;
            if (isNewSA)   // new SA
            {
                areaID = MakeSalesForceGUID();
                a = new SF_AREA
                {
                    ID = areaID,
                    DESCRIPTION = t.DESCRIPTION,
                    CU_NUMBER = Convert.ToString(t.CU_NUMBER),
                    FC = t.FC,
                    PROJECT = cp.ID,
                    DELETE_FLAG = "I"
                };
                ctx.SF_AREA.AddObject(a);


                SAID = MakeSalesForceGUID();
                sa= new SF_SUB_AREA
                {
                    ID = SAID,
                    PROJECT_REGION = t.CR,
                    AREA = areaID,
                    DELETE_FLAG = "I"
                };
                ctx.SF_SUB_AREA.AddObject(sa);
            }
            else       // old SA
            {
                List<SF_AREA> lia = (from a2 in ctx.SF_AREA
                                             join a2 in ctx.SF_SUB_AREA on a2.ID equals sa2.AREA
                                             where sa2.ID == t.SUB_AREA
                                             select ct2).ToList();
                if ((lia != null) && (lia.Count > 0))
                {
                    a = lia[0];
                    a.DELETE_FLAG = "U";
                    a.CLIENT_UNIT_NUMBER = Convert.ToString(t.CU_NUMBER);
                    a.DESCRIPTION = t.DESCRIPTION;
                    a.FC = t.FC;
                    a.PROJECT = cp.ID;
                } // TODO: throw an error here for else block

                List<SF_SUB_AREA> lisa = (from sa2 in ctx.SF_SUB_AREA
                                                              where sa2.ID == t.SUB_AREA
                                                              select sa2).ToList();
                if ((lisa != null) && (lisa.Count > 0))
                {
                    sa = lisa[0];
                    sa.PROJECT_REGION = t.AREA;
                    sa.AREA = lisa[0].AREA;
                    sa.DELETE_FLAG = "U";
                }
            }
            ...
            ctx.SaveChanges(); // left out the try/catch

Currently I’m just creating new context every time I commit something, but I don’t know if this is advisable.

            foreach (SF_MOVE_ORDER mo in liMO ) {
                using (SFEntitiesRM ctx2 = new SFEntitiesRM())  // new context for every MO since it goes into an unknown state after every commit
                {
                    List<SF_CLIENT_PROJECT> liCP = (from cp in ctx2.SF_CLIENT_PROJECT
                                                    where cp.ID == mo.CLIENT_PROJECT
                                                    select cp).ToList();
                    if ((liCP != null) && (liCP.Count > 0))
                    {
                        PerformMoveOrder(mo, liCP[0], ctx2);
                    }
                }
            }
  • 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-08T17:34:25+00:00Added an answer on June 8, 2026 at 5:34 pm

    Usually with errors like this, it is best to start out by saving one object and building in the complexities one at a time. That way, you can start to figure out where the problem lies. It can end up being somewhere down the object graph that you weren’t even expecting. But I would not just continue to throw the whole LINQ update at the context. Break it up into smaller saves and rebuild it to the largets graph and you’ll find your error.

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

Sidebar

Related Questions

I need to know which iOS device is currently running app (saying more exactly
I have a daemon app written in C and is currently running with no
I'm currently working on an OpenGL ES 1.1 app for the iPad its running
I am currently running a web app that sees several (~15) users logging in
I get a very confusing crash where I am currently running out of my
I'm currently developping an iPad app which is using OpenGL to draw some very
I'm currently developing an app running on android api 4 (1.6) and above. However,
I am currently running a simple rails app on heroku. However, it seems to
I am currently running into an issue trying to create delegates from MethodInfo .
I am currently running Kobold 1.0.4 and cannot work out how to use Box2D

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.