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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:32:16+00:00 2026-05-22T11:32:16+00:00

I am using Visual Studio 2008 with .NET Framework 3.5. I am trying to

  • 0

I am using Visual Studio 2008 with .NET Framework 3.5.

I am trying to do what I had thought would be a simple deletion of some rows using LINQ to entities.

I have a simple SQL Server database back end and I am using Data Entity Framework to access it. I have done nothing to the default behavior created in the EDMX.

I am attempting the following code:

            myDB.Dispose();
            myDB = new EChODatabaseConnection();


            //get our equipment list of requested equipment
            var OldEquip = from u in myDB.dbEquipmentRequestedSet
                                          where u.iRequestID == requestID
                                          select u;
            myDB.DeleteObject(OldEquip);

            myDB.SaveChanges();

It gets to the db.DeleteObject(OldEquip) and generates the following error:

“The object cannot be deleted because it was not found in the ObjectStateManager.”

I have verified that there is something in OldEquip before the line of code is executed.

I added the first two lines of code(Dispose and new) on the off chance there was an issue with previous code.

EDIT
The dbEquipmentRequestedSet looks like this:

iRequestID  (in db an int)
sCode       (in db a varchar(50))
SCodePrefix (in db a varchar(10))

I use a composite primary key based upon iRequestID and sCode.

EDIT2
To clarify, in almost all cases, the OldEquip query will result in more than one result.

From the answers so far, it appears that I will have to manually go through each entry to delete.

Is there a more elegant solution? Maybe by using a stored procedure?

  • 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-22T11:32:16+00:00Added an answer on May 22, 2026 at 11:32 am

    Sounds like you want to delete multiples. Try this:

    var OldEquip = (from u in myDB.dbEquipmentRequestedSet
                                where u.iRequestID == requestID
                                select u)
                        .ToList();
    
    foreach(var item in OldEquip)
    {
        myDB.DeleteObject(item);
    }
    

    The likely cause if that DeleteObject accepts an object, which should be an entity that is contained in the ObjectStateManager.Your code currently passed it an ObjectQuery<T> which isn’t contained in the ObjectStateManager.

    More at this MSDN forum post.

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

Sidebar

Related Questions

Using Visual Studio 2008, and I'm trying to use some of the .net Framework
I am using Visual Studio 2008 SP1 with .NET Framework sp1. I am not
I'm using Visual Studio 2008, .net Framework 3.5 for a Windows forms client-server app
I am using Visual Studio 2008 targeting .net 3.5 framework. I need to add
I am using Visual Studio 2008 with .NET Framework 3.5. I have a DataGrid
Using Visual Studio 2008 I've built a COM object that targets the .Net Framework
I am new to the .NET Framework. I am using Visual Studio 2008 in
I am using Visual Studio 2008 with the .NET Framework (v3.5). I cannot seem
I'm using Visual Studio 2008, with .net framework, C++/CLI. My program only runs in
We have an ASP.Net MVC 1.0 solution developed using Visual Studio 2008 and .net

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.