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 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

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?
I attempt to use webservice return POCO class generated from entity data model as
I made a subclass of CMFCCaptionBar in what has so far been a vain
I've been using tcpdump (version 4.1.1) to attempt to capture wireless frames from a
I've been trying to deploy a c# console app that I made to a
In an attempt to add some parameter validation and correct usage semantics to our
I have a C# 4.0 Winform app that I just upgraded from 3.5 to

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.