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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:14:38+00:00 2026-06-05T13:14:38+00:00

Each task has a reference to the goal it is assigned to. When I

  • 0

Each task has a reference to the goal it is assigned to. When I try and delete the tasks, and then the goal I get the error

“Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.” on the line _goalRepository.Delete(goalId);

What am I doing wrong?

 [HttpPost]
    public void DeleteGoal(int goalId, bool deleteTasks)
    {
        try
        {
            if (deleteTasks)
            {
                Goal goalWithTasks = _goalRepository.GetWithTasks(goalId);

                foreach (var task in goalWithTasks.Tasks)
                {
                    _taskRepository.Delete(task.Id);
                }
                goalWithTasks.Tasks = null;
                _goalRepository.Update(goalWithTasks);

            }

            _goalRepository.Delete(goalId);

        }
        catch (Exception ex)
        {
            Exception deleteException = ex;
        }
    }
  • 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-06-05T13:14:40+00:00Added an answer on June 5, 2026 at 1:14 pm

    Most likely the problem is because you’re attempting to hold onto and reuse a context across page views. You should create a new context, do your work, and dispose of the context atomically. It’s called the Unit Of Work pattern.

    The main reason for this is that the context maintains some state information about the database rows it has seen, if that state information becomes stale or out of date then you get exceptions like this.

    There are a lot of other reasons to use the Unit of Work pattern, I would suggest you do a web search and do a little reading as an educational exercise.

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

Sidebar

Related Questions

I have queue of tasks for the ThreadPool, and each task has a tendency
I have a SQLite DB containing tasks. Each task has a date, and there
I have this problem of scheduling tasks. Each task has a suggested start time
I have an ObservableCollection of Task objects. Each Task has the following properties: AssignedTo
My task is to simulate activity of couple of persons. Each of them has
I have an application which performs 30 independent tasks simultaneously using multithreading, each task
Suppose that I have users, tasks and each task belongs to a batch. Each
This should be an absurdly easy task: I want to take each line of
I have a task to operate on complex number. Each number consists of double
I have an unordered tree. Each node represents a task that can be done

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.