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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:37:21+00:00 2026-05-12T18:37:21+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.

This is the error message I am getting when I try to run the following, roughly:

1 DataContext db = new DataContext();
2 o = new object();
3 o.association = db.GetAssociatedObject(pId);
4 db.objects.InsertOnSubmit(o);
5 db.SubmitChanges();

This code creates a new object, populates an association with an existing object, then inserts the new object. When I comment out line 3+4, the error goes away. What causes the error? Can I not do an insert with associated objects?

  • 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-12T18:37:21+00:00Added an answer on May 12, 2026 at 6:37 pm

    The error message is misleading. This is a bit more complicated, but I found the error.

    I have a method that is trying to save a detached object, and create associations for it.
    This method creates a new attached copy of the object and copies all the members. It then creates the association.

    Say I have object A that is detached. My method tries to read it from database so that I have the attached version of it. Say this is object A. A is being updated with all the members that changed.
    A needs to get an association with objects of type C, via a many-to-many relationship called B: A <= B => C

    I assigned the detached copy of A to B. This caused the exception. Once I assigned the correct instance of A, it worked.

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

Sidebar

Related Questions

Has there been any attempt and creating a formalized method for organizing CSS code?
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
If I attempt to connect to Mac OS X 10.5 Leopard's built in vnc
When you attempt to declare an unsigned variable in C#.NET with a value outside
I've decided to attempt using the double submitted cookies technique to attempt to prevent
This is an attempt to rephrase a question I asked earlier. I'd like to
When I attempt to use the iterator form of parsing for a Spirit grammar
For some reason when I attempt to make a request to an Ajax.net web
I am using the following code to attempt to read a large file (280Mb)

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.