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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:11:30+00:00 2026-05-13T06:11:30+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.”

I have scene a lot of solutions dealing with the Attach() method but I’m just trying to add in a new record. Not sure what is going on.

Here is my code, It is failing on the star’d line.:

try
            {
                LINQDataContext datacontext = new LINQDataContext();


                TrackableItem ti = datacontext.TrackableItems.FirstOrDefault(_t => _t.pkId == obj.fkTrackableItemId);
                arcTrackableItem ati = new arcTrackableItem();
                ati.barcode = ti.barcode;
                ati.dashNumber = ti.dashNumber;
                ati.dateDown = ti.dateDown;
                ati.dateUp = ti.dateUp;
                ati.fkItemStatusId = ti.fkItemStatusId;
                ati.fkItemTypeId = ti.fkItemTypeId;
                ati.partNumber = ti.partNumber;
                ati.serialNumber = ti.serialNumber;
                ati.archiveDate = DateTime.Now;

                datacontext.arcTrackableItems.InsertOnSubmit(ati);
                datacontext.SubmitChanges();


                arcPWR aItem = new arcPWR();
                aItem.comments = obj.comments;
                aItem.fkTrackableItemId = ati.pkId;
                aItem.fkPWRStatusId = obj.fkPWRStatusId;
                aItem.PwrStatus = obj.PwrStatus;


                **datacontext.arcPWRs.InsertOnSubmit(aItem);**
                datacontext.SubmitChanges();
  • 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-13T06:11:31+00:00Added an answer on May 13, 2026 at 6:11 am

    Looks like obj was built using a different dataContext and that needs to be created using the same dataContext rather than instantiating a new one.

    A quick solution might be to pass in a dataContext rather than instantiating a new one inside this method.

    • 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
I made an application that copies a database that has been premade and then
I attempt to use webservice return POCO class generated from entity data model as
I've been trying to deploy a c# console app that I made to a
When I attempt to connect to an intranet web service from a web application
I am aware this topic has been raised severals, however i have a slight
I have a C# 4.0 Winform app that I just upgraded from 3.5 to
I am having a C# (.NET 3.5, VS2005 Professional) application that uses unmanaged 32bit

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.