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 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
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
I've been using tcpdump (version 4.1.1) to attempt to capture wireless frames from a
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

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.