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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:15:22+00:00 2026-05-12T23:15:22+00:00

An attempt has been made to Attach or Add an entity that is not

  • 0

An attempt has been made to Attach or
Add an entity that is not new, perhaps
having been loaded from another
DataContext. This is not supported.

Having worked with Linq to SQL for some time, I believe that I know about its limitations and that I follow the rules when I write new code. But it is frustrating to get this exception, as there is no indication of which object caused the violation. In complex data manipulation scenarios with multiple DCs, I can only think of trial-and-error to narrow down the possible culprits. Is there a way to find out more?

  • 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-12T23:15:22+00:00Added an answer on May 12, 2026 at 11:15 pm

    If you attach an object to your DataContext, it must have been created by you using the new operator. If you read the object from a DataContext, you must save it to the same DataContext.

    To alleviate these kinds of problems, I always use a single DataContext, and I do everything on a “unit of work” basis.

    Generally speaking, that means that, at any given time, I am reading the records I need, performing work on those records, and saving changes, all in a single unit of work, using a single DataContext. Since it is a unit of work, it doesn’t bleed over into other DataContext objects.

    If Linq to SQL is fighting you on this, I would examine your architecture and see if the way you are doing it is optimal, especially if you are finding it difficult to identify the object causing the error. In general it is difficult to share objects between DataContexts. You can do it (using things like “attach” and “detach”), but it’s a pain in the ass.

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

Sidebar

Related Questions

An attempt has been made to Attach or Add an entity that is not
An attempt has been made to Attach or Add an entity that is not
I've been getting several errors: cannot add an entity with a key that is
Has there been any attempt and creating a formalized method for organizing CSS code?
Following method shall only be called if it has been verified that there are
In an attempt to add some parameter validation and correct usage semantics to our
This is a pretty straight forward attempt. I haven't been using python for too
I'm trying to attach an entity in LINQ to SQL but it throws the
I have a C# 4.0 Winform app that I just upgraded from 3.5 to
This has been driving me insane. I can't seem to get the RewriteMap directive

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.