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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:56:00+00:00 2026-06-15T03:56:00+00:00

So I need to be able to edit my primary key field in my

  • 0

So I need to be able to edit my primary key field in my edit page for a row, 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.

When I don’t change the primary key field I can save all my other changes to my database.

This is my edit function.

//edit - post
[HttpPost]
public ActionResult ActiveCampaignsEdit(ActiveCampaign activecampaign)
{
  try
  {
    if (ModelState.IsValid)
    {
      db.Entry(activecampaign).State = EntityState.Modified;
      db.SaveChanges();
      return RedirectToAction("ActiveCampaigns");
    }
  }
  catch (DataException err)
  {
    //Log the error (add a variable name after DataException)
    ModelState.AddModelError(string.Empty, err.Message);
  }
  ViewBag.TypesList = new SelectList(db.Types, "TypeId", "TypeName");
  ViewBag.CaptureFormsList = new SelectList(db.CaptureForms, "Id", "Name");
  ViewBag.AssignedUsersList = new SelectList(db.Users, "Id", "Username");
  return View(activecampaign);
}

How would I go about editing the Primary Key, or am I approaching this in the wrong way?

  • 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-15T03:56:02+00:00Added an answer on June 15, 2026 at 3:56 am

    When using ORMs like Entity Framework, the UPDATE command is composed basically like this:

    UPDATE table 
    SET ChangedCol = ChangedVal 
    WHERE PrimaryKeyCol = PrimaryKeyValAtLoadTime
    

    Afterwards it checks the number of affected rows to match the expected value.

    So when you try to change the PK the update command will update no row and the check will fail.

    The real question is: Why do you want to change the primary key value?

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

Sidebar

Related Questions

I need to be able to get the primary key of an nserted row
I need to be able to edit messages in my error queue (so that
(Summary: My users need to be able to edit the structure of their dynamically
Users of the website need to able to store images in their area ,
I need to be able to edit vb.net code using visual studio without stopping
I need to be able to edit a table of data in the browser.
I need to be able to edit nodes from a client outside of Drupal
Need to be able to pull Magento products into an external template. Need to
I need to be able to access a list throughout my Rails project. For
I need to be able to search through multiple 2D arrays and search the

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.